Referencing PageItems associated with XML Elements
I have a .Net app that uses the ServicePortTypeClient to formulate script args and send them to a .jsx script that takes a data-generated json structure as an argument and uses prefab code to convert to reserialize as XML nodes and wraps them in Root and Story nodes. I want to change any prefab code as little as possible and am wondering how do I reference the ExtendScript DOM element associated from a known XML element after the PageItems have all been created. Do they have the same name and I'm supposed to use XmlElement.item('nameOfItem')?
My end goal is to use a Group to repeatedly group 3 elements together (a table header, a table, and an image) so they don't get split up across pages when there's isn't enough space for all three. (see json below) It looks like I cannot group XmlElements and have to group PageItems, hence the need to find the associated ones to the xml.
Sorry for the novice questions and I'm a little baffled by navigating the ExtendScript DOM.
Since I'm not able to debug the script curently the best I can do is demonstrate this is the json that gets passed in prior to being converted to XML:
{
"section": [
{
"h1": "general grouping 1",
"subsection": [
{
"h2": "table description (header) 1",
"Image": {
"@href": "somefilepath1.jpg"
},
"Table": "csv values for table1"
},
{
"h2": "table description (header) 2",
"Image": {
"@href": "somefilepath2.jpg"
},
"Table": "csv values for table2"
},
]
},
{
"h1": "general grouping 2",
"subsection": [
{
"h2": "table description (header) 3",
"Image": {
"@href": "somefilepath3.jpg"
},
"Table": "csv values for table3"
}
]
}
}Then after the above gets converted to XML it gets wrapped in this:
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<Root>
<Story>
<section>
</section>
</Story>
</Root>I was trying some code like this in the .jsx:
var xmlTag = myDocument.xmlElements[0];
var subsectionXmlItemArray = xmlTag.evaluateXPathExpression("//subsection");
for (var i=0; i<subsectionXmlItemArray.length; i++) {
var subsectionChildrenXmlItems = subsectionXmlItemArray[i].getElements();
var subsectionGroup = myDocument.groups.add(subsectionChildrenXmlItems); // errors here saying the parameter passed in is not the right type (it's XmlElement[], not PageItems[])
subsectionGroup.name = "subsection" + i;
}The above intent being for each subsection, add each element within it to a new group of their own. The comment in the snippet explains the need to access the PageItem derived from the XmlElement.
Thank you, thank you, thank you for any suggestions or directions to resources for understanding the InDesign ExtendScript DOM would probably be helpful as I've had a hard time locating good resources to learn this material. (I know of www.indesignjs.de for API documentation but a lot of the descriptions of object in the API are not very descript and the blog side of the site is in German)
