1 Reply Latest reply on Mar 25, 2011 8:54 AM by JohnDevlon

    [AS CS5] How to check if pageitem has associated xml element?

    JohnDevlon Level 1

      HI,

       

      Can anyone please help me?

       

      I would like to know if a pageitem has an associated xml element but I can't get it to work in applescript.

       

                                      set allItems to all page items of myCurrentPage


                                      repeat with aItem in allItems
                                          if not (associated XML element of aItem = null) then
                                              set currentXML to associated XML element of aItem
                                             
                                              if name of markup tag of currentXML is "myText" then

                                                   -- do something
                                              end if
                                             
                                          end if

       

                                      end repeat

       

      How do I check if a pageitem has an associated xml element? The code above doesn't solve the issue...

       

      Any feedback would be great.

       

      Kind regards

       

      John

        • 1. Re: [AS CS5] How to check if pageitem has associated xml element?
          JohnDevlon Level 1

          Hi,

           

          It took me lot of sleepless nights but i found a solution that works:

           

                    set allItems to all page items of myCurrentPage

                    repeat with c from 1 to number of items in allItems

                              set aItem to item c of allItems

           

                              set assXMLcheck to "valid"

           

                              try

                                   set assXMLcheck to (associated XML element of aItem) as string

                                   -- if the associated XML element is empty or not set

                                   -- the string will be set to "«constant ****nada»"

                                   -- In other cases, if the item has an associated xml element,

                                   -- this will raise an error and the string will not change

                              end try

           

           

           

                              if assXMLcheck is "valid" then

                                   set currentXML to associated XML element of aItem

                                   set currentXMLTag to markup tag of currentXML

                                   set currentXMLTagName to name of currentXMLTag

           

           

                                   display dialog currentXMLTagName

                              end if

           

                    end repeat

           

          It will not become part of earth history as most beautiful programming solution ever, but it works

           

          John