Search code examples
xpathuipathuipath-studio

On UiPath how can I extract (from an XML File) the second tag if there are multiple tags with the same name?


I have an XML File with this characteristics:

   <Root>
    <Example>
     <Address> Sesame Street </Address>
     <Address> New York US </Address>
    </Example>
    <Example>
     <Address> Nairobi KE</Address>
    </Example>
   </Root>

I want to extract always the second tag (New York US) or the first one if its only one tag. But on UiPath when i try to extract (with Execute XPath activity), it always returns the first one. Any suggestion on how can i extract the second one or the first if its the only one?


Solution

  • My understanding is you always want the last Address element in an Example, which can be accomplished by using the XPath function last() in the predicate.

    //Address[last()]

    This selects both the "New York US" and "Nairobi KE" elements.

    I'm a bit unclear on the question, but if your intent is to only extract "New York US", you can specify that you only want the last Address in the first Example.

    //Example[1]/Address[last()]