Finding Xml Elements - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
13: XML Rules
HAPTER
//XPath will match on every XML element in the XML structure.
this.xpath = "//*";
this.apply = function(myElement, myRuleProcessor){
}
}
}

Finding XML elements

As noted earlier, the subset of XPath supported by XML rules does not allow for searching the text
contents of XML elements. To get around this limitation, you can either use attributes to find the XML
elements you want or search the text of the matching XML elements. The following script shows how to
match XML elements using attributes. This script applies a color to the text of elements it finds, but a
practical script would do more. For the complete script, see FindXMLElementByAttribute.
main();
function main(){
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
var myRuleSet = new Array(new AddAttribute);
with(myDocument){
}
//Now that the attributes have been added, find and format
//the XML element whose attribute content matches a specific string.
var myRuleSet = new Array(new FindAttribute);
with(myDocument){
}
}
else{
alert("No open document");
}
function AddAttribute(){
this.name = "AddAttribute";
this.xpath = "/devices/device/part_number";
this.apply = function(myElement, myRuleProcessor){
with(myElement){
if(myCounter % 2 == 0){
myElement.texts.item(0).fillColor =
app.documents.item(0).colors.item("ColorB");
}
myCounter++;
}
//Do not process the element with any further matching rules.
return true;
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
XML Rules Examples 195

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents