Execute xpath in studio

Hello,

an xpath works when I test it on freeformatter but doesn’t work the same in uipath (the output is empty).

This is the xml structure - XPATH IS //ROUTE/text()

in uipath string(//ROUTE/text()) return empty value.

Any advice?

Tx

Hello @sanem3 ,

Could you please explain with the screenshot of the workflow and where you are getting the error.
I hope you are trying to add the xpath to the selector property. Share the screenshot and we can have a look.

Is a soap xml response

@sanem3
welcome to the forum

You need to handle the XML namespaces like here:

and as anternate:

1 Like

Thanks peter,

i’ve found something similar and it works:
xDoc.Descendants(nsCase+“ROUTE”).First().Value

where nsCase is the namespace contained after Q311B.

Now my question is: which are the difference between the “execute xpath” and the function used above (.descendants) to find a value within an xaml?

Descendants() is close to the behaviour of xpath //*
Descendants(“abc”) similar to XPath //abc

1 Like

Thank you for your reply.
In my case, where I always have to retrieve the same value, is namespace management necessary? If yes, for what reason?

it will not find the element with //elementname when a namespace is involved as the namespace part is part of the full name.

Setting up the namespace is little effort and more worth instead of setting up retrievals for local name only.

However for training purpose have a look on the local name only approaches:

xDoc.Root.Descendants().Where(Function (e) e.Name.LocalName.Equals("ROUTE")).First().Value
XPATH could work like this:

//*[local-name()='ROUTE']
1 Like

sorry but these are first approaches with xml. Is it a correct approach to create an harcoded variable like this:

nsCase = “urn:xlmsoa:abc”

and always use this expression to find the value?

xDoc.Descendants(nsCase+“ROUTE”).First().Value

or is there a possibility that the namespace or other changes over time?

Because in that case the alternative way would be to use a regex, what do you think?

Thank you

just share the xml or similar sample xml with us. thanks

we would not recommend it , as it can be processed with the for XML available options / techniques

as described within the linked post. Datatype has to be of XNamespace

when the namespace is corrrect prepared, then it will work

This is my test xml, which mirrors the original.

TestXml.xml (352 Bytes)

Of course, the nscase variable is of type xnamespace, is it correct to have the hardcoded namespace value? Or can this vary and is it better to retrieve it dynamically?

Appreciate your help.

it was necessairy to fix the xml (some tags were not properly closed)

Analysis:

so we do know which namespace we have to configure

and we can do the retrieval with the following options:
grafik

XPath:
grafik

or with the usage of a namespace manager

currently I am working on a custom library (Reply XMLToolBox Activities) to dynamize it and making it more easy. But there are some XML specifics to handle as well. So we would recommend for XML Beginers to configure the namespaces manually (currently you only need one with the descendants approach)

1 Like

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