Extract Data from XML file and store in an array

I have a XML, where i need to fetch all the values in “File File”

There are multiple places where the “File File”, has appeared. I need the value extracted in an array Variable.

As of now, I have been able to fetch only one value. Please help me fetch as many values in “File File”

WIP.xaml (6.5 KB)
XML_.xml (30.0 KB)

the XML is defining Namespaces which are to handle. Have a look here:
XML Extraction - Handling Namespaces (Tableau, Soap, OASIS types) - Help / Community - UiPath Community Forum

give a try at working with the Descendants(… method

A flow like this:

xnsDefault | Datatype: XNamespace =

xDoc.root.name.Namespace

Let us do the following

I used Assign Activity as follows.

Out (System.String) = xDoc.Root.Descendants(xnsDefault + “File”).Select(Function (x) x.Value).ToArray

Out Output is arriving as follows:
System.String

Where do i please need to rectify please

use the immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

We dont know the details, but when using a Variable of DataType: String() - a String Array you will not get the content, but the DataType when it is involved e.g. log Message, Write Line, using ToString()…

Also have a look at String.Join(" | ", yourOutPutVar)

1 Like

Yes i made use of Log. Enclosed screenshot. Please help where to make the change to get the output.

we already told:
use immediate panel for inspections

we mentioned:

and we gave the modified statement:

The datatype of Out has to be a String Array. We also suggest to use more meanfully variable Names within the best practice suggestions

@Manish_Bedi
we assume that all doubts are clarified now and also demonstrated the working suggestion within the immediate panel. So let’s close the topic by

Sorry Peter, I still did not get it.

In the Assign Activity, correct me that this is right ?

Out: DataType String = xDoc.Root.Decendants(xnsDefault + “File”).Select(Function (x) x.Value).ToArray

Any modifications needed to it …Apologies again for inconvenience

No, as mentioned it is returning a String Array

Thanks Peter,

Out: DataType Array of String = xDoc.Root.Decendants(xnsDefault + “File”).Select(Function (x) x.Value).ToArray

Now i Passed ‘Out’ variable to Log (info) activity, the output is
System.String

Any miss here

we already mentioned:

and when a flat string is needed:

I used Python

import xml.etree.ElementTree as ET

def extract_file_file_values(xml_data):
  """
  Extracts all values within "File File" tags from the given XML data.

  Args:
    xml_data: The XML data as a string.

  Returns:
    A list of values extracted from "File File" tags.
  """

  root = ET.fromstring(xml_data)
  file_file_values = []

  for element in root.iter('File'):
    if element.tag == 'File':
      file_file_values.append(element.text)

  return file_file_values

# Example usage:
# Assuming xml_data is the string containing the XML content
xml_data = """
<root>
  <File>Value1</File>
  <OtherTag>Some other data</OtherTag>
  <File>Value2</File>
  <AnotherTag>More data</AnotherTag>
  <File>Value3</File>
</root>
"""

extracted_values = extract_file_file_values(xml_data)
print(extracted_values)  # Output: ['Value1', 'Value2', 'Value3']

in Addition to above, we hope that it can now finalized:

as mentioned:

And omit Out as Variable name as it is a Keyword and can cause compiler confusions


follow the same…
15 value is getting

yes That works, Thanks a lot, everyone!

@Manish_Bedi

Perfect