activities
latest
false
UiPath logo, featuring letters U and I in white
Developer Activities
Last updated Nov 26, 2024

Get XML Node Attributes

UiPath.WebAPI.Activities.GetXMLNodeAttributes

Description

Retrieves the attributes of an XML Node.

Project compatibility

Windows - Legacy | Windows | Cross-platform

Cross-platform configuration

  • ExistingXMLNode - The XML Node whose attributes are to be retrieved. This field supports only XNode variables. For more information on XNode objects, go here.
Advanced options

Output

  • Attributes - An IEnumerable<XAttribute> variable containing the retrieved XML node attributes. For more information on XAttribute objects, go here.

Windows - Legacy, Windows configuration

Properties panel

Input

  • ExistingXMLNode - The XML Node whose attributes are to be retrieved. This field supports only XNode variables. For more information on XNode objects, go here.

Output

  • Attributes - An IEnumerable<XAttribute> variable containing the retrieved XML node attributes. For more information on XAttribute objects, go here.

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.
  2. Drag a Sequence to the Workflow Designer.

    • Create the following variables:

      Variable Name

      Variable Type

      Default Value

      XMLString

      String

       

      XMLNodes

      **IEnumerable<XNode>

       

      XMLDocument

      XDocument

       
  3. 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.
  4. 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.
  5. Place a Get XML Nodes activity after the Deserialize XML activity.

    • In the Properties panel, add the variable XMLDocument in the ExistingXML field and the variable XMLNodes in the XMLNodes field.
  6. Drag a For Each activity after 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.
  7. Select the Body of the For Each activity and create a new variable:

    Variable Name

    Variable Type

    Default Value

    XMLAttributes

    **IEnumerable<XAttribute>

     
  8. 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.
  9. Place a Get XML Node Attributes activity after the Write Line activity.

    • In the Properties panel, add the value node in the ExistingXMLNode field and the XMLAttributes variable in the XMLAttributes field.
  10. Drag a For Each activity after the Get XML Node Attributes activity.

    • To open the activity, perform a double click.
    • 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.
  11. Select the Body of the For Each activity.
  12. Drag a Write Line activity inside the Body container.

    • Add the expression attribute.Value in the Text field.
  13. 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.

Here you can download an example.

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.