Set the value of an XML node

Verified
Added by iNTERFACEWARE

Use node.setInner() to set the value of an XML node, only works for XML nodes

Source Code
    -- create sample XML node
   local x = [[
   <patient id ="">
      <first-name>John</first-name>
      <last-name>Smith</last-name>
   </patient>]]
   xmlMsg = xml.parse(x)
   trace(xmlMsg)
   
   -- change the surname (last-name element)
   local node = xmlMsg.patient["last-name"]:setInner('Wilson')
   trace(xmlMsg)
   --> last-name change from "Smith" to Wilson"
   
   -- you probably don't want to do this
   local node = xmlMsg.patient:setInner('Oops I replaced all the patient data...')
   trace(xmlMsg)
   --> patient replaced with "Oops..."
Description
Use node.setInner() to set the value of an XML node, only works for XML nodes
Usage Details

Use node.setInner() to set the value of any XML node. Warning: node.setInner() this allows you replace a non-leaf node (unlike node.setNodeValue() which raises and error), this means you can accidentally overwrite a node and sub-nodes, see the code for an example of how how (you don’t want) to do this.

Note: The node.setInner() function only works for XML node trees.

How to use the snippet:

  • Paste the code into your script