Copy link to clipboard
Copied
How to read xml elements in reverse order from the indesign structure panel??
I want to read the parent element of a particular element in a loop
Copy link to clipboard
Copied
Hi,
First of all, if you only need to retrieve string data from an element, I would definitively recomment using a XML object instead. It's much much faster.
var reverseXMLthroughObject = function() {
var doc, xf, xo, cs, c, n, arr = [];
if (!app.documents.length
|| !app.activeDocument.xmlElements[0].xmlElements.length) {
alert("Nothing to work with…");
return;
}
doc = app.activeDocument;
xf = File ( Folder.temp+"/tmp.xml");
doc.exportFile ( ExportFormat.XML, xf );
xf.open('r');
xo = XML(xf.read());
xf.close();
xf.remove();
cs = xo.xpath("*/*");
n = cs.length();
while (n--) arr[arr.length]=String(cs
);
return arr.join(",");
}
reverseXMLthroughObject();
However if you need to do work with xmlElements inside the indesign structure, you may try this way.
var reverseXMLThroughStructure = function() {
var doc, root, cs, c, n, arr = [];
if (!app.documents.length
|| !app.activeDocument.xmlElements[0].xmlElements.length) {
alert("Nothing to work with…");
return;
}
doc = app.activeDocument;
root = doc.xmlElements[0];
cs = root.evaluateXPathExpression("./*");
n = cs.length;
while (n--) cs
.texts[0].isValid && arr[arr.length]=cs .contents;
return arr.join(",");
}
reverseXMLThroughStructure();
Another approach is XMLRules.
Loic
www.ozalto.com
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more