1 Reply Latest reply on Nov 13, 2012 5:53 PM by conyip

    Fetch entire xml structure

    vincent 1982

      Hi,

       

      I am looking for a way to get the entire xml structure inside an actual xml object, or if possible, as a string. I need to pass it to a service but i haven't found a way to get it in the layout that it is shown in the structure panel. The only thing i am able to do is work with XMLElments but isnt there any other way to access it?

        • 1. Re: Fetch entire xml structure
          conyip Level 1

          if its importing then you can import the xml into javascript rather than indesign then manipulate the xml before placing it in indesign.

          for example, in this case the xml is read from a file into javascript:

          var xmlFile = File.openDialog ("Please select the XML file");

          xmlFile.open("r");

                              var strXML = xmlFile.read();

            xmlFile.close();

                              XML.ignoreComments = true;

                              XML.ignoreProcessingInstructions = true;

          xmlTree =  new XML(strXML);

          var childrenXML = XMLTree.children(); // children would be directly below the root element to select individual elements use .child("elementName") there are several other options available for navigating through the nodes: including: .parent() and also descendants().

           

          for (i =0;i < XMLTree.children().length; i++) {

          //process the xml

          }

           

          Keith