Insert an XML node

Added by iNTERFACEWARE

Use node.insert() to insert a node into an XML node tree

Source Code
   -- create sample XML node
   local x = [[
   <patient SSN ="">
      <first-name>John</first-name>
      <last-name>Smith</last-name>
   </patient>]]
   xmlMsg = xml.parse(x)
   trace(xmlMsg)
   
   -- insert an ATTRIBUTE - put id before SSN 
   xmlMsg.patient:insert(1,xml.ATTRIBUTE, 'id')
   trace(xmlMsg)
   
   -- insert an ELEMENT  - put middle name in the middle
   xmlMsg.patient:insert(4, xml.ELEMENT, 'middle-name')
   trace(xmlMsg)
   
   -- insert an TEXT element - before the names
   xmlMsg.patient:insert(3,xml.TEXT, 'Insert comment before names')
   trace(xmlMsg)
   
   -- insert a CDATA (unparsed text) element - before the names again
   xmlMsg.patient:insert(4, xml.CDATA, 'Because CDATA is not parsed it allows & and <>')
   trace(xmlMsg)