Skip to main content
Known Participant
October 24, 2012
Question

Fetch entire xml structure

  • October 24, 2012
  • 1 reply
  • 847 views

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?

This topic has been closed for replies.

1 reply

Known Participant
November 14, 2012

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