UiPath Activities

The UiPath Activities Guide

Get XML Node Attributes

UiPath.Web.Activities.GetXMLNodeAttributes

Retrieves the attributes of an XML Node.

Properties

Input

  • ExistingXMLNode - The XML Node whose attributes are to be retrieved. This field supports only XNode variables.

Output

  • Attributes - An IEnumerable<XAttribute> variable containing the retrieved XML node attributes.

Misc

  • Private - If selected, the values of variables and arguments are no longer logged at Verbose level.

Common

  • DisplayName - The display name of the activity.

Example of Using the Get XML Node Attributes Activity

The Get XML Node Attributes activity is used for processing .xml files.
To exemplify how to use this activity, we have created an example that reads an .xml file, converts it to an XML document, retrieves the individual nodes and writes an attribute and a value for each node.

This is how the automation process can be built:

  1. Open Studio and create a new Process.

Note:

Make sure to place the .xml file inside the project folder. For this example we used the XMLfiles.txt.

  1. Drag a Sequence to the Workflow Designer.
    • Create the following variables:
Variable Name
Variable Type
Default Value

XMLString

String

-

XMLNodes

**IEnumerable<XNode>

-

XMLDocument

XDocument

-

  1. Drag a Read Text File activity inside the sequence container.
    • In the Properties panel, add the name Read XML file in the DisplayName field.
    • Add the value "XMLfiles.txt" in the FileName field.
    • Add the variable XMLString in the Content field.
  2. Drag a Deserialize XML activity under the Read Text File activity.
    • In the Properties panel, add the variable XMLString in the XMLString field and the variable XMLDocument in the XMLDocument field.
  3. Place a Get XML Nodes activity below the Deserialize XML activity.
    • In the Properties panel, add the variable XMLDocument in the ExistingXML field and the variable XMLNodes in the XMLNodes field.
  4. Drag a For Each activity below the Get XML Nodes activity.
    • Add the value node in the Item field and the variable XMLNodes in the Values field.
    • Select the System.Xml.Linq.XNode option from the TypeArgument drop-down list.
  5. Select the Body of the For Each activity and create a new variable:
Variable Name
Variable Type
Default Value

XMLAttributes

**IEnumerable<XAttribute>

-

  1. Add a Write Line activity inside the Body container.
    • Add the expression node.XPathSelectElement("author").ToString in the Text field. This expression selects the name of the author from the .xml page and writes it in the Output panel.
  2. Place a Get XML Node Attributes activity below the Write Line activity.
    • In the Properties panel, add the value node in the ExistingXMLNode field and the XMLAttributes variable in the XMLAttributes field.
  3. Drag a For Each activity below the Get XML Node Attributes activity.
    • Double click to open the activity.
    • Add the value attribute in the Item field and the variable XMLAttributes in the Values field.
    • In the Properties panel, select the System.Xml.Linq.XAttribute option from the TypeArgument drop-down list.
  4. Select the Body of the For Each activity.
  5. Drag a Write Line activity inside the Body container.
    • Add the expression attribute.Value in the Text field.
  6. Run the process. The robot extracts an attribute and a value from the nodes, in this case, the name of the author and the book id, and displays them in the Output panel.
     
     
    Download example

Updated 8 months ago


Get XML Node Attributes


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.