Article View: adobe.scripting.indesign
Article #2190Re: Changing Values in XML tags
From: Gary_Vidal
Date: Mon, 12 Jan 2009 16:29
Date: Mon, 12 Jan 2009 16:29
29 lines
1959 bytes
1959 bytes
XmlRules is optimized for this type of processing. The recursive approach works fine for small documents but when using large documents suffers dramatically.
Here is a sample rule that selects all sections elements and title elements from a proposed book content. It just pumps them into an array. You can modify the getArticleSections in conjuction with the xpath variable to grab the information you want.
var xpath = ["//article_root/article_section","//article_root/article_title"];
var articleSections = getArticleSections(xpath);
//At this point, myXMLMatches contains all of the XML elements
//that matched the XPath expression provided in myXPath.
function getArticleSections(myXPath){
var myXMLElements = new Array;
var myRuleProcessor = app.xmlRuleProcessors.add(myXPath);
try{
var myMatchData = myRuleProcessor.startProcessingRuleSet(app.documents.
item(0).xmlElements.item(0));
while(myMatchData != undefined){
var myElement = myMatchData.element;
myXMLElements.push(myElement);
myMatchData = myRuleProcessor.findNextMatch();
}
myRuleProcessor.endProcessingRuleSet();
myRuleProcessor.remove();
return myXMLElements;
}
catch (myError){
myRuleProcessor.endProcessingRuleSet();
myRuleProcessor.remove();
throw myError;
}
}
Technical Details
Message-ID:
<59b7651b.14@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossingReferences:
<59b7651b.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,d78f6b73256f6f00 X-Google-Attributes: gidf939a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Gary_Vidal@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.scripting.indesign Subject: Re: Changing Values in XML tags Message-ID: <59b7651b.14@webcrossing.la2eafNXanI> Date: Mon, 12 Jan 2009 08:29:36 -0800 References: <59b7651b.-1@webcrossing.la2eafNXanI> Lines: 36 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit