I tried to import an simple XML with the ExtendScript Toolkit on InDesign CS5 Server with the following script:
var myXmlFile = new File("../path/blubb.xml");
myXmlFile.open("r", undefined, undefined);
myContent = myXmlFile.read();
var xml_value = myContent.childNodes.getElementsByTagName('ROOT').nodeValue;
//var xml_value = myContent.getElementsByTagName('ROOT').item(0).firstChild.nodeValue;
the XML-FIle is this:
<?xml version="1.0" encoding="UTF-8"?>
If i alert myContent, there is the whole XML in the terminal output in one line. And the console of the ExtendScript Toolkit says "Execution finished. Ergebnis: undefined". (why is the result: unfinished?)
Now i tried to get some nodeValues in different ways (from different tutorials) but sometimes theres an error "myContent.getElementsByTagName is not a function". So i tried different ways, without this functions but if i tried to access the nodes like this:
var xml_value = myContent.item;
or some other compositions with "firstChild", "item[x]" and "nodeValue", there is the error message "undefined is not an object".
Could anyone please give me a hint, how to read the xml-data in a loop? I need to parse some XML-FIles from InDesign-CS2-Documents and create new InDesign-CS5-Documents, but stucked already at the first step...
Thanks for your reponses!
InDesign needs to know that it's actually XML, so make sure to use an XML object.
Use something like this:
myXMLFile = File ('path+ filename + '.xml'); myXMLFile.open('r'); var currentXML = new XML(myXMLFile.read());
There's more documentation on E4X here: Use E4X. There's a tutorial here: https://developer.mozilla.org/en/E4X_Tutorial