How to search a "string" text in XML file in UiPath

XML.xml (17.2 KB)
In the XML document, we require search whether a string “Java” or “.jar” is present or not and output a BooleanValue . How can we perform the task.

We assume that the XML is deserialized - xDoc

the most simple check would be

Assign Activity:
hasFound = {“JAVA”, “JAR”}.Any(funtion (x) xDoc.ToString.ToUpper.Contains(x))

But we recommend to be more specific and define where to search in detail at XML level e.g.

Element values
Attribute values

UPD1 - fixing:

to Contains

@Manish_Bedi,

You can use Read text file activity to read the xaml file. This will return string variable. Once you have it, check by this condition. strVariable.Contains("Java") or strVariable.Contains(".jar")

Thanks,
Ashok :slight_smile:

I applied this, for Assign

(xDoc.ToString.Contains(“Java”)) Or (xDoc.ToString.Contains(“.jnlp”)) Or (xDoc.ToString.Contains(“.jar”))

but its says not correct. Please help

share details. Who is saying this, the result, the Compiler…?

Kindly note:

  • we recommend to avoid redundancies so we suggest(ed)
{"JAVA", ".JAR",".JNLP"}.Any(funtion (x) xDoc.ToString.ToUpper.Contains(x))

ensure the correct "

You can test all rnds within the immediate panel and also we recommended to be more specific and avoiding XML handling on string level (e.g. it would also match a xml comment)

When i use the above value, a red sign appears. says it is not right. Wish to check whether the function is complete, because it appears something is missing.

Hi @Manish_Bedi

=> Use Read Text File activity to read the XML document and store the output in a variable xmlContent

=> Use Deserialize XML and pass input as xmlContent and store the output in a variable xmlDoc

=> Use the below syntax in Assign activity:

isPresent = xmlDoc.Descendants().Any(Function(e) e.Value.Contains("Java") Or e.Value.Contains(".jar") Or e.Value.Contains(".jnlp"))

isPresent is of DataType System.Boolean

Regards

When i enter i receive compiler error

I used:
xDoc.Descendants().Any(Function(e) e.Value.Contains(“Java”) Or e.Value.Contains(“.jar”) Or e.Value.Contains(“.jnlp”))

Error ERROR Validation Error Syntax error, ‘,’ expected
Non-invocable member ‘Function’ cannot be used like a method.
The name ‘e’ does not exist in the current context
Using the generic type ‘Or<TLeft, TRight, TResult>’ requires 3 type arguments Sequence3.xaml

ensure which programming language is set within your project and let us know it.

its C# programming language set for the project

Changed to VB mode and it works. Thank you

1 Like