This content has been marked as final. Show 3 replies
In the help file I read
An XML element.
void select ([existingSelection: SelectionOptions=REPLACE_WITH])
Selects the XMLElement.
(where the selection options are Optional).
So at first sight your code appears correct.
>But it is not working.
That doesn't help any who'd like to help you. You will have to elaborate.
A few hints:
Perhaps your variable
is not defined. If that's the case, give up trying to write code for this complicated job! XML is not the easiest part of ID to begin with. Starting with uninitialized variables and flagging that as an error (and complaining about that in a forum) is a beginners' blunder.
If I run your script line with i set to 0, the first element of my XML structure is selected. I can see with my own eyes it works, because I have the XML Structure pane in ID open. If I click on the 2nd element there and run your script line, the top (= 0th) element is selected. Perhaps you didn't open the XML Structure view so you did not see it worked after all. Or perhaps you expected something
to be selected -- the text content, maybe -- so you tag it as "error". That's a misinterpretation of what the XmlElement object is. Understandable, but still not an error. You can have lots of XmlElements without any text or other object associated. If it was your intention to select whatever the xml element contains, try working with the property 'xmlContent'. From its description I gather that sort-of does this alternative interpretation, i.e., you can select the
which is pointed to by the element. Untried. But do read on.
If I run your script with i = 1, I
get an error, and it's perfectly valid too! "Object is invalid" -- well, of course it is. There is no other XML element at that level. An app.document.xmlelements entry always points to the
of the XML, and you can only have one. Perhaps you expected #1 to be the next sub-element. Well, not so in the ID implementation -- as usual for almost all XML based structures, it's a tree. The "next" element is xmlElements.xmlElements, which you can check by changing your line to
and verifying the 2nd element from the top is selected in the XML Structure view.