3 Replies Latest reply on Dec 17, 2010 6:59 AM by The Flex Viking

    XPATH + //

    The Flex Viking Level 1

      I am trying to use the XPATH expression "//" to find all matches of an element name no matter where they exist in the XML document.  For example ..

       

      count(//process_data/xml_data//User)

       

      it correctly returns a value of 5 on my test XML document.  Great.  How would I go about grabbing the 3rd match or perhaps iterating through all matches?

       

      I have tried the following

       

      //process_data/xml_data//User[1]

       

      this works.  However, the following doesn't work

       

      //process_data/xml_data//User[2]

       

      It says the XML variable I assign the expression to is <empty>

       

      I even tried to get it to work with a list variable (xml subtype) and assign //process_data/xml_data//User to the variable.  That doesn't work, it shows <list><null/></list> as the result.

      I created an xml variable and assign //process_data/xml_data//User to the variable.  That doesn't work, it only shows the 1st match.

       

      Any ideas?

       

       

      One of the LC Knowledge bases specificaly says this.

       

      /process_data/formVariable/object/data/xdp/datasets/data//TextField1 returns "Hello world 1...", "Hello world 2...", and "Hello world 3..." and therefore is more flexible if the exact structure of an XML is not known (for example, when using a relative path).

        • 1. Re: XPATH + //
          Steve L Walker Level 5

          LC is pretty finicky. Although you may define a process variable as an int and use it as a List or XPath index you still have to wrap it in a number function. For example,

           

          //process_data/xml_data//User[number(process_data/@cnt)]

           

          rather than

           

          //process_data/xml_data//User[process_data/@cnt]

           

          Give it a try.

           

          Steve

          1 person found this helpful
          • 2. Re: XPATH + //
            MarcelBoucher Adobe Employee

            Looks like you have encountered a bug in the product .

            While the //Person xPath query does in fact return the correct number of nodes found within the XML source, it appears that there is some eroneous logic in processing the xPath statement when nodes are childeren of a different parent. For example, when I run some tests on the XML you sent me:

             

            <Root>
              <Engineers>
                <Person name=”Bruce” />
               <Person name=”John” />
              </Engineers>
              <Administrators>
                <Person name=”Sarah” />
               <Person name=”Paul” />
              </Administrators>
              <Students>
                <HighSchool>
                  <Person name=”Maggie” />
                </HighSchool>
              </Students>
            </Root>

             

            I can infact return node //Person[1] and Person[2] which are children of <Engineers/>. LC seems to not be able to locate the <Person/> nodes under <Administrators> and <Students/>.

             

            I will log this on your behalf. I tried several alternatives with setValue but I was unable to find a workaround. My only suggestion is to create a custom component and implement SAX APIs to locate the values you need.

            1 person found this helpful
            • 3. Re: XPATH + //
              The Flex Viking Level 1

              Steve ... Yes, I had tried wrapping my index in a number() function.  And to make sure that wasn't the issue, I hard coded the number [2] and it still didn't work.

               

              Marcel ... Yup.  I just built a DSC to work around the issue.