Copy link to clipboard
Copied
Hi,
i have an xml structure like this (without indent, just for better readability here):
<root>
<master>
<graphic_0 control="XXXX" href="File:///test.png"/>
<textframe_0>
<textframe_1>
<text_1>DUMMY</text_1>
</textframe_1>
<text_0 control="XXXX">DUMMY</text_0>
</textframe_0>
</master>
</root>
As you can see, the <graphic_0> and the inner <text_0> element both have a "control" attribute. I'd like to get ALL elements with a control attribute, no matter in which level they are located.
I tried this:
// given: master is the <master> element
var xmlElements = master.evaluateXPathExpression("//*[@control]");
alert(xmlElements.length);
But the alert always returns 1 (the <graphic_0> element), but not the inner <text_0> element.
What am I doing wrong?
EDIT: graphic_0 (that one recognized) represents a rectangle, text_0 a few tagged words
Hi @patMorita , try this:
var r = app.activeDocument.xmlElements
var x = r.firstItem().evaluateXPathExpression("//*[@control]");
$.writeln(r.count()) //returns 1
$.writeln(r.firstItem().markupTag.name) //returns root
$.writeln(x.length) //returns 2
$.writeln(x[0].markupTag.name) //returns graphic_0
$.writeln(x[0].xmlAttributes[0].name) //returns control
Also check this helpful thread on the .evaluateXPathExpression method:
...
Copy link to clipboard
Copied
Hi @patMorita , try this:
var r = app.activeDocument.xmlElements
var x = r.firstItem().evaluateXPathExpression("//*[@control]");
$.writeln(r.count()) //returns 1
$.writeln(r.firstItem().markupTag.name) //returns root
$.writeln(x.length) //returns 2
$.writeln(x[0].markupTag.name) //returns graphic_0
$.writeln(x[0].xmlAttributes[0].name) //returns control
Also check this helpful thread on the .evaluateXPathExpression method: