2 Replies Latest reply on Nov 1, 2016 8:06 AM by Loic Aigon

    Extendscript xml with dash element node


      Hi all,


      How do you access to an xml element with dash inside it? And modify it?











      I try with

      myxml.bookstore.Author.book-en="toto"-->Not work

      myxml.bookstore.Author.('book-en')="toto"-->Not work

      myxml.bookstore.Author.child(1)="toto"-->Not work


      Please, can you help me??? Thx a lot!! ;-)



        • 1. Re: Extendscript xml with dash element node
          Dirk Becker Level 4
          var x = <xml><test-ing>Hello</test-ing>, <ot-her>World!</ot-her></xml>;
          x["test-ing"] = "Good bye";
          • 2. Re: Extendscript xml with dash element node
            Loic Aigon Level 2

            Dirk's answer is obviously one the smartest. Let me help you understanding where you were wrong.



            fails because of the dash obviously



            Fails because you, by using parens, indicates a condition which is here kind of undefined : 'book-en' so what…



            Fails because you are misusing the child function as it expects a string and not an index.


            So you could have used


            myxml.bookstore.Author.children()[0] = "titi";

            The less precise because you can't presume the first child is kind of book-en.

            Similar to /root/bookstore/Author/*[1] in xpath


            myxml.bookstore.Author.child ( "book-en" )[0] = "tata"

            You are here targeting the first child of type "book-en"

            Similar to /root/bookstore/Author/book-en[1] in xpath




            You are here using a condition to retrieve only nodes of the children list whose name matches 'book-en'

            Similar to /root/bookstore/Author[name(.)='book-en'][1] in xpath


            myxml.bookstore.Author.descendants("book-en")[0] = "tutu";

            This is the most global approach as it would look at any descendants from the starting node.

            Similar to /root/bookstore/Author//book-en[1] in xpath


            But once again, Dirk's answer is the smartest one you want to use.