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.

System.Xml.XPath.XPathEvaluator+d_1`1[System.Object].

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

Thanks
Ashwin S

Thanks Ashwin

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

hi @KT1993
cHECK THIS POST THIS SURELY WILL HELP YOU

IF NOT TELL ME THE EXACT SCENARIO

Thanks
Ashwin S

XML

output

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”

Copper_DecisionTable_XML.Root.Element(“record”).Value.ToString

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

//record[@A][@B][@leadtime]
or use individually

//record[@A]

Thanks
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

Thanks
Ashwin S

@AshwinS2

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,

Thanks,
Karthik.

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

<Records-Set>
  <record>
    <A>...</A>
    <B>...</B>
    <C/>
    <D/>
    <E>True</E>
    <Leadtime>12</Leadtime>
  </record>
  ...
</Records-Set>

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.

3 posts were split to a new topic: XPath providing Object and not a String

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.