Copy link to clipboard
Copied
Hi,
I am facing some issues in xml xpath result order. Its not returning the correct order.
1. case 1 - Its returning mixing order. - Created Manually
2. case 2 - Ascending order (correctly) - Export xml from case 1 and imported into new document.
3. case 3 - Decending order (Returning reversely) - Export xml from case 1 and imported into new document and placed the elements into pages.
I don't know the reason of this issue. But there is no change in the xml structure.
There is any reason behind this?? How can I get the correct order (case 2)??
Code:
var root = app.activeDocument.xmlElements[0];
xpth = "//comp";
alert("xpth "+xpth)
var elts = root.evaluateXPathExpression(xpth);
alert("elts Length " + elts.length);
for(var cnt = 0; cnt < elts.length; cnt++)
{
cElt = elts[cnt];
cElt.select()
alert(cElt .contents)
}
Copy link to clipboard
Copied
Hi,
1. case 1 - Its returning mixing order. - Created Manually
That might be not surprising. As you create items randomly, you are reordering the xmlElements collection on the fly. That would mean that evaluateXPathExpression loops through the collections to retrieve compliant items. So if the collection is messy, the expected order is messy.
2. case 2 - Ascending order (correctly) - Export xml from case 1 and imported into new document.
Ok.
3. case 3 - Decending order (Returning reversely) - Export xml from case 1 and imported into new document and placed the elements into pages.
Weird one.
I think it may be helpful to not work with xmLElement.evaluateExpression at all. Or Rather, I would collect everySingle xmlElement evaluateXPathExpression("//*") and add an indesign inner id attribute to the xmlElement. I would also store those ids/xmlElement pairs to an object.
Once that done, export XML, loads XML File and do xpath there. Once you have items the right way, look at xml node inddID and retieve the XMLElement reference in the database object.