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

uiautomation
xml

#1

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

#2

hi @KT1993

Check the below posts

Thanks
Ashwin S


#3

Thanks Ashwin

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


#4

hi @KT1993
cHECK THIS POST THIS SURELY WILL HELP YOU

IF NOT TELL ME THE EXACT SCENARIO

Thanks
Ashwin S


#5

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]


#6

hi @KT1993

use this xpath in execute xpath

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

//record[@A]

Thanks
Ashwin S


#7

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)"


#8

hi @KT1993

try to use * instead of var1 and var2

Thanks
Ashwin S


#9

@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 ?


#10

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

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


#11

Hi ,

Please find below tutorials,

Thanks,
Karthik.