XML
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
XML ayrıştırma
function parseXml() {
// Load an XML representation of your campaigns.
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<campaigns>',
'<campaign id="28632346">Placement Campaign 1</campaign>',
'<campaign id="28780216">Campaign #14</campaign>',
'<campaign id="29606506">LotsOfExclusion</campaign>',
'</campaigns>'
].join('');
const document = XmlService.parse(xml);
const root = document.getRootElement();
const entries = document.getRootElement().getChildren('campaign');
for (let i = 0; i < entries.length; i++) {
const id = entries[i].getAttribute('id').getValue();
const name = entries[i].getText();
console.log('%s) %s (%s)', (i + 1).toFixed(), name, id);
}
}
XML oluşturma
function createXml() {
// Create and log an XML representation of your campaigns.
const root = XmlService.createElement('campaigns');
const campaignIterator = AdsApp.campaigns().get();
while (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
const child = XmlService.createElement('campaign')
.setAttribute('id', campaign.getId().toFixed(0))
.setText(campaign.getName());
root.addContent(child);
}
const document = XmlService.createDocument(root);
const xml = XmlService.getPrettyFormat().format(document);
console.log(xml);
}
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-21 UTC.
[null,null,["Son güncelleme tarihi: 2025-08-21 UTC."],[[["\u003cp\u003eThe provided Google Apps Script code snippets demonstrate how to parse and create XML data for Google Ads campaigns.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eparseXml\u003c/code\u003e function reads XML data, extracts campaign ID and name, and logs them to the console.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecreateXml\u003c/code\u003e function iterates through existing Google Ads campaigns, generates XML elements for each, and logs the formatted XML output.\u003c/p\u003e\n"]]],[],null,["# XML\n\nParse XML\n---------\n\n```transact-sql\nfunction parseXml() {\n // Load an XML representation of your campaigns.\n const xml = [\n '\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e',\n '\u003ccampaigns\u003e',\n '\u003ccampaign id=\"28632346\"\u003ePlacement Campaign 1\u003c/campaign\u003e',\n '\u003ccampaign id=\"28780216\"\u003eCampaign #14\u003c/campaign\u003e',\n '\u003ccampaign id=\"29606506\"\u003eLotsOfExclusion\u003c/campaign\u003e',\n '\u003c/campaigns\u003e'\n ].join('');\n\n const document = XmlService.parse(xml);\n const root = document.getRootElement();\n\n const entries = document.getRootElement().getChildren('campaign');\n for (let i = 0; i \u003c entries.length; i++) {\n const id = entries[i].getAttribute('id').getValue();\n const name = entries[i].getText();\n console.log('%s) %s (%s)', (i + 1).toFixed(), name, id);\n }\n}\n```\n\nCreate XML\n----------\n\n```gdscript\nfunction createXml() {\n // Create and log an XML representation of your campaigns.\n const root = XmlService.createElement('campaigns');\n const campaignIterator = AdsApp.campaigns().get();\n\n while (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n\n const child = XmlService.createElement('campaign')\n .setAttribute('id', campaign.getId().toFixed(0))\n .setText(campaign.getName());\n root.addContent(child);\n }\n const document = XmlService.createDocument(root);\n const xml = XmlService.getPrettyFormat().format(document);\n console.log(xml);\n}\n```"]]