5 Replies Latest reply on Mar 5, 2013 1:39 AM by thomas.jeorge

    move element




      I want to move my child element <tag4> before its parent element <tag3>.


      From this



      To this:





      Please suggest the js code.




        • 1. Re: move element
          [Jongware] Most Valuable Participant

          That would be



          app.activeDocument.xmlElements.item(0).xmlElements.item(0).xmlElements.item(1).xmlElements .item(0).move (LocationOptions.AFTER, app.activeDocument.xmlElements.item(0).xmlElements.item(0).xmlElements.item(0));



          --- typed from memory so it's in the neighbourhood of one or two xmlElement nesting levels.

          • 2. Re: move element
            thomas.jeorge Level 1

            Hi Jong,


            The script only changes in first instance. I want to move all the Tag4.

            Please look into this.







            Jongware you are awesome. Thanks for support.



            • 3. Re: move element
              thomas.jeorge Level 1

              Waiting for positive reply.

              • 4. Re: move element
                [Jongware] Most Valuable Participant

                Ah, so it wasn't meant for a one-shot move.


                Then you can (a) loop over all XML Elements, check for "Tag4", and move them individually, or -- as suggested in another XML related post -- use 'evaluateXpathExpression' to quickly gather all Tag4'. Next, all you have to do is a "move", but in this case you don't know the absolute position to move to. So you can use "BEFORE", together with the current tag's Parent.

                Here's how:


                var tagList = app.activeDocument.xmlElements[0].evaluateXPathExpression("//Tag4");
                for (i=tagList.length-1; i >=0; i--)
                  tagList[i].move(LocationOptions.BEFORE, tagList[i].parent);



                1 person found this helpful
                • 5. Re: move element
                  thomas.jeorge Level 1

                  Thanks, Jongware. You are genius.