Read an empty XML TEXT element

Added by iNTERFACEWARE

Demonstrates the best way to read an empty XML TEXT element, by using the text(' ') function from the xml.lua module

Source Code
require 'xml'

function main(Data)
   -- Parse the XML message
   local XML = xml.parse(Data)
   
   -- ORIGINAL CODE: Will cause errors with empty TEXT elements
   
   --local FirstName = XML.patients.patient["first-name"][1]:nodeValue()
   
   --local LastName = XML.patients.patient["last-name"][1]:nodeValue()
   
   --local SSN = XML.patients.patient["social-security-no"][1]:nodeValue()
   
   
   -- RECOMMENDED BEST PRACTICE: Use the text() funcion from the xml module
   
   -- FINAL CODE: Does not cause errors with empty TEXT elements
   
   local FirstName = XML.patients.patient["first-name"]:text():nodeValue()
   
   local LastName = XML.patients.patient["last-name"]:text():nodeValue()
   
   local SSN = XML.patients.patient["social-security-no"]:text():nodeValue()
   
end
Description
Demonstrates the best way to read an empty XML TEXT element, by using the text(' ') function from the xml.lua module