Xml check if name exist

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

Check the need of handling XML namespaces as described here:

A Namespace and XPath demo you can find here:

1 Like

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

Lets do it one by one:

Typical Desrialization flow looks like this:
grafik

we do debug and use the immediate panel:


confirm the statement with enter, enter

we can check for the elment names:
grafik
and we do have the namespace portions within the name and we need to handle it:
grafik
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

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

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.

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

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