CHAPTER 13: XML Rules Scripting the XML-rules Processor Object 205
main();
function main(){
var myXPath = ["/devices/device"];
var myXMLMatches = mySimulateXPath(myXPath);
//At this point, myXMLMatches contains all of the XML elements
//that matched the XPath expression provided in myXPath.
function mySimulateXPath(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;
}
}
}