Kumar802
(Kumar802)
June 10, 2022, 2:40pm
1
Hi,
I have the following xml
XMLT.txt (575 Bytes)
I need to know whether or not a name given as input is present within the various <NAME-SEARCH-12 tags
My XPATH is the following:
/FUNCTOUT/SEARCH-12/NAME-SEARCH-12[./text()=‘FRANK’]
but in UiPath, through the “Execute XPATH” activity, it doesn’t work, any suggestion?
Thanks in advance
ppr
(Peter Preuss)
June 10, 2022, 2:54pm
2
Check the need of handling XML namespaces as described here:
Going ahead
Serializing the XML - output: xDoc | DataType: XDocument:
[grafik]
Checking if we have to handle XML namespaces
[grafik]
We do have:
[grafik]
Checking for some children:
[grafik]
Defining Namespace Variable
[grafik]
In some cases, we can also do: Assign Activity - xnsDefault = xDoc.Root.Name.Namespace
Checkin the retrieval
[grafik]
xDoc.Descendants(xnsDefault + "productVersion")
GetDescendants { [<productVersion build="456" xmlns="http://tableau.com/api">123</…
A Namespace and XPath demo you can find here:
@Fabian_DDD
I do feel that a XPath Approach is better for the retrieval
Setting up a NamespaceManager with a Config Datatable:
[grafik]
for the default namespace with empty prefix “def” is assigne as prefix
the retrieval is configured as another datatable (could also be externalize into an excel)
[grafik]
I did also for a deeper nested element for demo purpose
After all preperation it is iterating over the retrieval config and retrieves the specfied values. et voila:
[grafik]
So this …
1 Like
Kumar802
(Kumar802)
June 10, 2022, 3:14pm
3
So in my case, in order to iterate between the various NAME-SEARCH-12, and check whether the input name is present, it is necessary to create a datatable containing the various namespaces?
Is it not possible to simply search with the shared xpath?
Sorry but this is the first approach and I can’t decipher the reading of the tags
ppr
(Peter Preuss)
June 10, 2022, 3:55pm
4
Lets do it one by one:
Typical Desrialization flow looks like this:
we do debug and use the immediate panel:
confirm the statement with enter, enter
we can check for the elment names:
and we do have the namespace portions within the name and we need to handle it:
first line fails
second using the NOT recommended {xxx}ElementName way but suceeds
Also the XPATH requires the info for the namespace. We can prototype it following:
here we are using the an access with the local name only, and would fail when we ommit the namespace (your reported case from above)
it allowed to reduce code redundancies but feel free to handle it different
Fazit:
working with locale name can maybe short cut, but also can have unwanted side effects
working with namespaces makes it more transparently and traceable
a balanced approach could be the described Descendants(… approach along with XNamespace variable and elementname
ppr
(Peter Preuss)
June 10, 2022, 4:02pm
5
Targeting your request. A minimal implementation could look like this:
Variables:
Prototypes and Insides:
Testline:
xDoc.Root.Descendants(xnsDefault2 + “NAME-SEARCH-12”).Any(Function (x) x.Value.ToUpper.Trim.Equals(“FRANK”))
for working with immediate panel also have a look here:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum
1 Like
Kumar802
(Kumar802)
June 13, 2022, 9:59am
6
thank you,
it works perfectly.
If I wanted to search instead, passing it the name in input, for example MARK, what is the associated email? Assuming there is MAIL after the name.
ppr
(Peter Preuss)
June 13, 2022, 10:03am
7
Let’ scope 1 topic = 1 case as researchers can easier find solutions for their cases.
May we ask you to create a new topic for the new question and if possible also share some sample data with us. Thanks
1 Like
system
(system)
Closed
June 16, 2022, 10:04am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.