Append an XML node

Introduction

This code demonstrates how to use the built-in node.append() to append an XML node to an XML node tree. The node.append() function creates and appends a new node to a specified (parent) XML Node.

Code to Append an XML Node [top]

  -- create sample XML node
   local x = [[
    <patient>
       <first-name>John</first-name>
      <last-name>Smith</last-name>
   </patient>]]
 xmlMsg = xml.parse(x)
 trace(xmlMsg)
 
 -- append an ATTRIBUTE
 xmlMsg.patient:append(xml.ATTRIBUTE, 'id')
 trace(xmlMsg)
 
 -- append an ELEMENT
 xmlMsg.patient:append(xml.ELEMENT, 'middle-name')
 trace(xmlMsg)
 
 -- append a TEXT element
 xmlMsg.patient:append(xml.TEXT, 'This is a text comment')
 trace(xmlMsg)
 
 -- append a CDATA (unparsed text) element
 xmlMsg.patient:append(xml.CDATA, 'Because CDATA is not parsed it allows & and <>')
 trace(xmlMsg)

Using the code for Appending an XML node [top]

The code demonstrates how to append a node to an XML node tree.

How to use the code:

  1. Paste the code into the main module of your channel.
  2. Then modify the code to suit your requirements.

More Information [top]

Tagged:

Please don't hesitate to take anonymous feedback survey or leave us a comment.

Leave A Comment?