Fetch XML node value (with condition on other node values) using Execute Xpath utility in UIPath

In order to fetch XML node value in UIpath I followed below steps.

I read the XML file using Read file utility .
Deserialized the XML using Deserialize XML activity.
in Execute Xpath activity I used the output variable of Deserialize XML as input and below given Xpath.

“Records-Set/record[A = ‘abc’][B=‘123’]/@Leadtime
but while printing it to a msgbox It just prints below given string in the message box.


Please help me on this .

below is the XML I am using.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> def 456 True 12 abc 123 True 12

hi @KT1993

Check the below posts

Ashwin S

Thanks Ashwin

but I already went through all these posts but they could not help me out :frowning:

hi @KT1993


Ashwin S



if I use below stateement in Assign activity I can fetch the value of all the attributes under element records as shown in the msgbox screenshot above but instead I just need the value of Leadtime and with a condition where A=“abc”


I need the XPATH for such scenario . the below given works well in other XML tools
Records-Set/record[A = ‘abc’][B=‘123’]/Leadtime[1]

hi @KT1993

use this xpath in execute xpath

or use individually


Ashwin S

Thanks Ashwin :slightly_smiling_face:

using below statement in Execute Xpath utility is working fine for me.
“string(/Records-Set/record[A = ‘abc’][B=‘123’]/Leadtime)”

though I have a new challange now , to make this Xpath dynamic . can anyone help me with the syantx for dynamic Xpath…

I used this below given statement but its not working as expected :frowning:
“string(/Records-Set/record[A = '”+var1+"’][B=’"+var2+"’]/Leadtime)"

hi @KT1993

try to use * instead of var1 and var2

Ashwin S


var1 and Var2 are the name of the variables which will be used to pass the values into statement at runtime.
how can repalcing them with * would work ?

using below statement in Execute xpath utility helped me at last :slight_smile:

“string(/Records-Set/record[A = '”+var1.ToString+"’][B=’"+var2.ToString+"’]/Leadtime)"

Hi ,

Please find below tutorials,


Slightly old thread, but thought I would just put some details in here to help those searching.

using below statement in Execute xpath utility helped me at last :slight_smile:

“string(/Records-Set/record[A = '”+var1.ToString+"’][B=’"+var2.ToString+"’]/Leadtime)"

If the XML looks the same


You can shorten your XPATH expression a little by search for //record instead of the ROOT element /Records-Set/record....

So it looks like

"//record[A = '" + var1 + "'][B = '" + var2 + "']/Leadtime"

It’s not much in this particular example, but for deeply nested structures, starting from the root would get messy.

And as you figured out, wrapping your XPATH expression in the String() function returns the string value of the single node, for a parent element string() would return the string values of each of the child nodes.

Friends, im trying to fetch the url from this XML

i tried like this but im not getting correct output

pls help me out

Hi @kgbheem,

To help others to assist you, many find it beneficial when the raw text or an example file to work with where possible, this way someone can spend less time speculating or back and forth banter to mimic the particular scenario.

I mocked up part of the XML from your image

<MultimapPresentation version="1.0.41" client="dealerdirect">
  <locationData type="storefinder">
    <prevPageUrl />
    <nextPageUrl />
    <location id="1">
        <param name="busid">2640</param>
        <param name="zip">06374-2034</param>
        <param name="url">http://www.google.ca</param>
        <param name="preown">1</param>

In your original XPath Query

This would be searching the XML for any matching <record> nodes that contain with a child-node <name> with a value of url.

The expected XML would look something like the following and would return an Object of matching the query, in this case just the 2nd <record>.


If you were to wrap the query in a string() e.g. string(//record[name='url']) it would return the string instance of each child node’s value concatenated together. e.g. url107.

There are many ways to go about querying with XPath, looking back at your example, the absolute query would be:


Shortening the query to look for matching <record> that contains <param name="url">... you’re missing a node level along with reference to the attribute.


finally, you’d want to convert XPath object to a string using the fn:string() function turning the query into


Alternatively, you can also use the XMLDocument methods such as XPathSelectElements if you didn’t want to use the Execute XPath activity.

Hope that clears it up!


Thank you so much @twhitehead.