Adobe 0046100128056 - InDesign - Mac Manual page 196

Javascript
Table of Contents

Advertisement

C
13: XML Rules
HAPTER
}
}
function FindAttribute(){
this.name = "FindAttribute";
this.xpath = "/devices/device[@part_number = 'DS001']";
this.apply = function(myElement, myRuleProcessor){
}
}
}
The following script shows how to use a JavaScript regular expression (RegExp) to find and format XML
elements by their content (for the complete script, see FindXMLElementByRegExp):
main();
function main(){
if (app.documents.length != 0){
var myDocument = app.documents.item(0);
var myRuleSet = new Array (new FindByContent);
with(myDocument){
}
}
else{
alert("No open document");
}
function FindByContent(){
//Find descriptions that contain both "triangle" and "pulse".
var myRegExp = /triangle.*?pulse|pulse.*?triangle/i
this.name = "FindByContent";
//XPath will match on every description in the XML structure.
this.xpath = "/devices/device/description";
this.apply = function(myElement, myRuleProcessor){
app.documents.item(0).swatches.item(-1);
}
}
function myResetFindChangeGrep(){
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
}
}
The following script shows how to use the
complete script, see FindXMLElementByFindText):
myElement.parent.xmlAttributes.add("part_number",
myElement.texts.item(0).contents);
return true;
myElement.xmlElements.item(0).texts.item(0).fillColor =
app.documents.item(0).swatches.item(-1);
return true;
var elements = xmlElements;
__processRuleSet(elements.item(0), myRuleSet);
if(myRegExp.test(myElement.texts.item(0).contents) == true){
myElement.texts.item(0).fillColor =
}
return true;
method to find and format XML content (for the
findText
XML Rules Examples 196

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents