4 Replies Latest reply on Oct 11, 2008 4:49 PM by [Jongware]

    Find beginning and end of an XMLtag in text

    Dave Pepper Level 1
      I am trying to find the beginning and end of an xml tag in a block of text using a script. Does anybody have any ideas on how to locate the beginning and end of an xml tag in text?

      You can see the ends of a tag visually from the user interface by the colored brackets that appear. So one of my ideas is to use a function to find the brackets. Does anyone know if those brackets have a character number, or some way to identify them?
        • 1. Re: Find beginning and end of an XMLtag in text
          Level 1
          what are you trying to do ? why you need to find these "brackets" ?

          why you can't go from other side - iterating XML collection ?

          if you go to UI and select this bracket and hit F8 - you will see on INFO palette UNICODE code 0xFEFF - but there is no IdSpecialCharacter for XML "brackets" - you can only find it as unicode code

          robin

          --
          www.adobescripts.com
          • 2. Re: Find beginning and end of an XMLtag in text
            Dave Pepper Level 1
            Thanks Robert,
            The reason why I'm doing this is I want to be able to select text in a document and determine if the selected text is a existing xml tag. And if it is not, I want it to make one.

            To do this, I am comparing the contents of the associated xml element (of the selection) with the contents of the selected text itself. When I compare the contents of the associated xml tag and the selected text, sometimes the bracket characters prevent my script from correctly finding matchs. So I need to remove all instances of the brackets from my strings.

            So is there a way to find the UNICODE value of a character in scripting?
            • 3. Re: Find beginning and end of an XMLtag in text
              Dave Pepper Level 1
              Robert, I was able to extract a value from the character using the AscW function. The value I got was -257. Is there any way to verify this is the same value as 0xFEFF.
              • 4. Re: Find beginning and end of an XMLtag in text
                [Jongware] Most Valuable Participant
                -257 is 0xFEFF (as a signed 2 byte word).

                I don't think that's a terribly reliable way of checking XML tags (I seem to remember this is more an internal "IsNotUsual" code for ID). And you don't know if it's a start or end tag.

                Your script may or may not pick up this code in the selected string, depending on where you start and end your selection. You can use regular string functions to remove them from the string.

                Perhaps it's better to walk over the XML tree and check if each element's start and end value ("storyOffset" for the start, a quick eyeballing of the help didn't reveal a good candidate for its end) is at the start and end of your selection.