Friday, July 28, 2006

 

The Emaciated, Anonymous, Invisible Parent of Root

You would think that the Root element would be the bottom of the XML element parental tree. After all, that's what the structure panel shows. But if you ask for:
app.activeDocument.associatedXMLElement.markUpTag.name;
you'll be surprised to get an error: "Object does not support the property or method 'markUpTag'"--how can this be?

Well, it turns out that the Root element is not the end of the line when it comes to traversing the XML elements of your document. There's another element that serves as the parent of the Root element. This particular element is somewhat emaciated. It does not have the full capabilities of a regular XML element.

Contrast the result of:
app.activeDocument.associatedXMLElement.properties.toSource()
which returns:
({storyOffset:0,
parentStory:null,
contents:"",
id:1,
parent:resolve("/document[@name=\"Untitled-2\"]"),
index:-1})
with the result of:
app.activeDocument.associatedXMLElement.xmlElements[0].properties.toSource()
which returns:
({storyOffset:1,
parentStory:null,
markupTag:resolve("/document[@name=\"Untitled-2\"]//XML-tag[@id=171]"),
contents:"",
id:2,
parent:resolve("/document[@name=\"Untitled-2\"]/XML-element[@id=1]"),
index:0})
See how this second xmlElement, which in fact is the Root element, has more properties than the first. One of those properties is a markUpTag, so let's take a look at that:
app.activeDocument.xmlTags.itemByID(171).properties.toSource();
returns:
({name:"Root",
tagColor:1766613612,
id:171,
label:"",
parent:resolve("/document[@name=\"Untitled-2\"]"),
index:0})
So there you have it, the emaciated, anonymous, invisible parent of Root.

Update *** Warning


Knowing that this element is there can be important if you're debugging a script that stumbles upon it, but please have the discipline to leave it alone. Attempts to change the values of its properties will at best fail and there is some danger of crashing InDesign. The reason this element is anonymous and invisible in the UI is precisely because it is not a regular XML Element to be used along with all the others.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?