3 Replies Latest reply on Feb 11, 2010 5:18 AM by Anil Yadav

    selecting the content of XML element CS3(JS)


      I am trying to select the whole content of XML Element.

      I am trying like this


      But it is not working.

        • 1. Re: selecting the content of XML element CS3(JS)
          [Jongware] Most Valuable Participant
          In the help file I read

          Class: XMLElement
          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.
          • 2. Re: selecting the content of XML element CS3(JS)
            [Jongware] Most Valuable Participant
            A few hints:

            Perhaps your variable
            i i
            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
            i else
            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
            i text
            which is pointed to by the element. Untried. But do read on.

            If I run your script with i = 1, I
            i do
            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
            i root
            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[0].xmlElements[0], which you can check by changing your line to


            and verifying the 2nd element from the top is selected in the XML Structure view.
            • 3. Re: selecting the content of XML element CS3(JS)
              Anil Yadav Level 1