1 Reply Latest reply on Jun 4, 2012 12:07 AM by Loic.Aigon

    [AS][CS4] Recursive XML element function

    JohnDevlon Level 1

      Hi,

       

      Does anyone have any experience in using a recursive XML element function in Applescript and Indesign CS4?

       

      I would like to do a search for a XML element based on the text who has the xml attachted.

       

       

       

      tell application "Adobe InDesign CS4"

                tell active document

                          set myXMLElement to XML element 1

       

                          repeat with i from 1 to the number of items of XML elements of myXMLElement

                                    my SearchXML(item i of XML elements of myXMLElement)

                          end repeat

       

                end tell

      end tell

       

      on SearchXML(elm)

                tell application "Adobe InDesign CS4"

                          set myText to contents of elm

       

                          repeat with i from 1 to the number of items of XML elements of elm

                                    my SearchXML(item i of XML elements of elm)

                          end repeat

       

                end tell

      end UpdateXMLData

       


      For some reason myText doesn't contain the text but an XML structure !!!! (something like

      XML element id 3 of XML element id 2 of document "test.indd")

       

       

      I've used the same structure in Javascript and the contents property gives the text back !

       

      What I'm I doing wrong? How can I get the text contents of the xml element?

       

      Thanks

        • 1. Re: [AS][CS4] Recursive XML element function
          Loic.Aigon Adobe Community Professional

          Hi,

           

          I would definitively recommend you to avoid recursing within the xml structure as it's freaking slow ! Instead I do use evaluate XPath expression :

           

           

          tell application "Adobe InDesign CS5.5"
                    tell XML element 1 of active document
            evaluate XPath expression using "//tag[.='foo']"
                    end tell
          end tell
          

           

          => returns a list of all xmlElements whose markup tag name is "tag" and where the contents is "foo".

          Then you can iterate through the list.

           

          Loic