On an XML file I use the following XPath expression to get search for a specific value:
/StandardBusinessDocument/message/transaction[descendant::additionalTradeItemIdentificationValue[text()="“001293"”]]/entityIdentification/contentOwner/gln/text()[1]
I pasted the XML in an online Xpath tester (xpather.com ) and tested the Xpath expression:
Here it works, I get the value I expect.
I tried doing the same thing in UiPath Studio:
The result is empty.
Does anyone has a view on what I am doing wrong?
where these steps used inside the XPath
In the Properties panel, add the variable XMLString
in the XMLString field.
Add the value "string(/catalog/book/author/text()[1])"
in the XPathExpression field. This expression extracts the text found in the author field from the xml
file.
Add the variable Result
in the Result field.
Cheers @Pascal_Hakkers
ppr
(Peter Preuss)
October 29, 2019, 1:50pm
4
@Pascal_Hakkers
Can you please Check and confirm that your XML is Not defining any namespace e.g.within the upper Elements.
In Case you are unsure Just Log Out the Name ptoperty from the root element and maybe subsequent elements
@ppr
Thanks for you reply.
Yes, there are indeed namespaces in the XML. Does this need a different Xpath selector?
ppr
(Peter Preuss)
October 29, 2019, 2:46pm
6
@Pascal_Hakkers
this should be the explanation for the behaviour. With logging out the element name you can verify if it is in use.
Here is an approach on how to handle without xpath (Me too I do like to work with xpath as well)
Hi @mikamol
Find the attached sample Main.xaml (8.1 KB)
that is showcasing following:
Retrieving all Field elements
Retrieving all Id elements (Parent is Field)
Retrieving the particular Answer Value for a particular Id
As this XML is defining the namespace:` xmlns="urn:abou:documents:ka:Case
The Root element Name is not Case it is: e.g. urn:abou:documents:ka:Case:Case
So the namespace part is to take into account
Solved with using namespace manager
Kindly note the order from a XML Docu…
In case of your structure is not too complex you may go with the local name trick:
@KMota
While I was working on your issue, you solved by yourself. Great
xpath: “string(//*[local-name()=‘nNF’]/text()[1])” would return the value.
Go on with the API that you currently used in your solution. I feel its easier to use on the start. And you are doing similiar, working with the local name.
And it was the issue with the namespaces.
A namespace let you allow to group elements in so called namespaces. In case you have more namespaces in use and e.g. some elements have the sam…
ppr
(Peter Preuss)
October 30, 2019, 6:03pm
7
@Pascal_Hakkers
thanks for update via message -
Sometimes it does make sense to start XML Processing learning/experience within a lighweight way:
working with reduced data / subset of the data
as in your case maybe removing namespace definitions if there is no name collision
Let us know if further help is required. Happy Automation