Get multiple nodes action in XML
- Dernière mise à jour2023/04/25
Get multiple nodes action in XML
The Get multiple nodes action in the XML package enables you to retrieve the value of multiple nodes.
Settings
- Session name
- Enter the session name defined in the Start session action. You can enter the session name directly or select the string variable that contains the session name.
- XPath expression
- Enter the XPath expression to retrieve multiple nodes or select an existing string variable that contains the XPath expression.
- Get each node
- Specify the node details to retrieve the node value. The following options are
available:
- Text value: Select to retrieve the text value of the node specified in XPath expression.
- XPath expression: Select to retrieve the defined XPath expression.
- Specific attribute name: Select and specify the attribute name of a node within the XPath expression to retrieve the attribute value.
- Assign the output to variable
- Specify a table variable to hold the retrieved values of the nodes. The extracted values are stored in the first cell of the table.
Example of how to retrieve the value of multiple nodes
Create an XML file named xml_sample with the following sample and
save it to your desktop folder:
<Customer>
<Cust_Details>
<custid city="Leon">A001</custid>
<custname>XYZ Corp</custname>
<custzipcode>15639</custzipcode>
<country>Mexico</country>
<Locale lang="es">Spanish</Locale>
</Cust_Details>
</Customer>
The following example illustrates how to retrieve the values of multiple nodes from a customer details:
- Create and name the bot: XML_Bot.
- Start an XML session by using the
action.
- The session name is set as Default automatically in Session name.
- Select and click Browse to select the XML file available on your desktop in Data Source. The file path is autopopulated. For example, C:\Desktop\xml_sample.xml.
- Double-click Get multiple nodes
action to add it to the editor.
- The session name defined in the Start session action is autopopulated in Session name.
- Enter //Customer/Cust_Details/custid in the XPath Expression.
- In the Get each node field, select from the following
options and print the output in the message box.
- Text value
- XPath expression
- Specific attribute name of each node, If you select this option then enter the attribute city in the text box.
- In the Assign the output to variable (optional) field,
select TableXMLNodes.
The first cell of the table variable holds the extracted values.
- Double-click or drag the Message box to print the values and
enter $TableXMLNodes[0][0]$ in the Enter the
message to display field.
The message box displays the extracted value stored in the first cell of the table.
- Click Save and then click Run.
The values retrieved from each node are as follows:
- Text value: A001
- XPath expression: /Customer/Cust_Details/custid
- Specific attribute name of each node: Leon