1 Reply Latest reply on Oct 21, 2010 9:08 AM by Barqx

    [InD. CS5 Server][JS] XML-Import, how to receive data?

    Sybriz

      Hello everybody!

       

      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");
      var myContent;

      myXmlFile.open("r", undefined, undefined);

      while(!myXmlFile.eof)

      {

           myContent = myXmlFile.read();

           var xml_value = myContent.childNodes[0].getElementsByTagName('ROOT').nodeValue;

           //var xml_value = myContent.getElementsByTagName('ROOT').item(0).firstChild.nodeValue;

       

           alert(xml_value);
      }

       

      the XML-FIle is this:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <ROOT>
           <TEST>blubb</TEST>
           <TEST2>bla</TEST2>
      </ROOT>

       

      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[0];

       

      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!

       

      Greetings

      Sybriz