Copy link to clipboard
Copied
I have given XMLElements (that are already tagged) and i need to get the tagged pageItem from the xmlElement, no matter if its a textFrame, a rectangle with a placed graphic or a word in a story.
I tried it with
var pageItem = element.xmlContent.parent;
// Returns Rectangle for tagged Rectangle
// Returns Document for tagged TextFrame (i need the Texframe)
// Returns Story for tagged Text (i need the Text)
What's the best apporach to get the tagged PageItem for the XMLElement?
Copy link to clipboard
Copied
Hi @patMorita the XMLElement object has a pageItems property that you could check. Here are the other XMLElement properties:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#XMLElement.html
Or you can go the other way and check for a pageItem’s or text’s associatedXMLElements property:
var p = app.activeDocument.selection[0].paragraphs;
var x;
for (var i = 0; i < p.length; i++){
if (p[i].associatedXMLElements.length != 0) {
x = p[i].associatedXMLElements;
for (var j = 0; j < x.length; j++){
$.writeln(x[j].markupTag.name)
};
}
};
Copy link to clipboard
Copied
Thank you rob,
I tried pageItems before. But pageItems is always empty (length 0). The other approaches aren't suitable for what i'm planning to do. 😕
Thats why i checked all other properties and for xmlContent it says "The text content or page item referred to by the element. Can return: Text, Story, PageItem, Movie, Sound, Graphic, Table or Cell." But the returned objects aren't what they should be (check initial question)
Copy link to clipboard
Copied
Urgs. my bad.
While writing the answer above i rechecked the code. And it has to be "xmlElement.xmlContent" and NOT "xmlElement.xmlContent.parent".