• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Order of xpath result values

Contributor ,
Feb 01, 2018 Feb 01, 2018

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)??

 

    XML_Structure.png

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)

}

TOPICS
Scripting

Views

540

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 02, 2018 Feb 02, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines