Skip to content

How do I remove data in the XML document at the given path or value

This example demonstrates how to remove data in the XML document at the given path or value within the context of an automated test in execution.

In this example, the XML data in which you have to remove values is stored and assigned a variable using the "store" command. Now by using the "xmlRemoveFromDocument" command, you can remove an XML value to the given path. The modified XML data is stored in the variable given in the value field.

Solution:

# Command Target Value
To store the XML data into a variable
1 store <?xml version="1.0" encoding="UTF-8"?>

<insuranceData>

<insurance category="valid">

<age>45</age>

<income>55000</income>

<zipcode>90001</zipcode>

<result>You are eligible for a subsidy.</result>

</insurance>

<insurance category="valid">

<age>64</age>

<income>25000</income>

<zipcode>14301</zipcode>

<result>You are eligible for a subsidy.</result>

</insurance>

<insurance category="invalid">

<age>15</age>

<income>25000</income>

<zipcode>08857</zipcode>

<result>Combinations of inputs provided out of scope for the calculator.</result>

</insurance>

</insuranceData>
Input_data
To remove data in the XML document in the given path
2 xmlRemoveFromDocument ${Input_data} || (/insuranceData/insurance[3]) InsuranceXmlData

Tips, Tricks, Gotchas & Best Practices:  

  • The XML should be valid and encoded in "UTF-8" format.
  • The new node value should be given in the XML path to remove the value. (Ex: /insuranceData//insurance[3]).
  • You can use the "xmlAssertPathExists" command to check if the path is valid or invalid


Feedback and Knowledge Base