0

When you're in the "structure" pane in Indesign you can choose to export it as XML.

Export XML

Using the exportFile function supported by extendscript I was able to get the file written to a file.

I'd like a way to get this XML into an variable, without writing a file to my disk.

Is there a way to do this ? What am I missing ?

El Dorado
  • 313
  • 1
  • 2
  • 14

2 Answers2

1

Yes and no. The simplest achievement would be to export the document as XML file. Then load the XML file as an Object like :

var xmlFile = File ( Folder.desktop+"/myXML.xml" );
app.activeDocument.exportFile ( ExportFormat.XML, xmlFile );
xmlFile.open('r');this 
var xmlObject = XML ( xmlFile.read() );
xmlFile.close();
xmlFile.remove();
alert( xmlObject.toXMLString() );

But of course, you could try to build this xml object without passing through that external object while browsing InDesign DOM XMLElements objects and pass those values to the object. But It would be really cumbersome imho.

Loic
  • 2,173
  • 10
  • 13
0

The Structure elements are called XMLElements

The root of the structure will be app.documents[0].xmlElements[0]

You can select an element using evaluateXPathExpression method of XMLElement object passing the xpath expression to select your XML node. The selected element can be assigned to a variable as an object

var myXmlSelection = app.documents[0].xmlElements[0].evaluateXPathExpression("/book/chapter")[0];

You can use placeXML method to place referenced element into a textFrame

myXMLElement.placeXML(myTextFrame)
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23