Skip to content

How do I set the "attributename" and "attributevalue" in given nodes of an XML document

This example demonstrates setting an attribute name and value to a given node in XML document.

In the solution shown below, the attribute name and value are being set for a given node using the "xmlSetNodeAttributes" command. The attribute "id" is added with value being "InsuranceDetails" for the "insurance" node. This is same as adding attribute name and value to a particular tag in HTML document.

Solution:

# Command Target Value
Store the XML in a variable
1 store <insurance><age>45</age><income>20000</income><zipcode>08817</zipcode><result>You are eligible for a subsidy.</result></insurance> XML
To set the "attributename" and "attributevalue" in given nodes of an XML document
2 xmlSetNodeAttributes ${XML} || {/insurance, {id,InsuranceDetails}} UpdatedXML

Tips, Tricks, Gotchas & Best Practices:  

  • To add two or more attribute names and values for a given node in XML document, the syntax is "xml_string || {path, {attributename,attributevalue},{attributename,attributevalue}}"
  • The XML should be valid and encoded in "UTF-8" format.
  • As a best practice, it is advised to define the variable names without any spaces and if you want to differentiate the words, use underscores.

Feedback and Knowledge Base