• Iguana 6
  • Previous Versions
  • API
  • Sample Code
  • Training
  • Create a Ticket
iNTERFACEWARE Help Center
  • Iguana 6
  • Previous Versions
  • API
  • Sample Code
  • Training
  • Create a Ticket

Code Repository

Home›Code Repository›xml.lua
Modules

xml.lua

Verified Featured
Added by iNTERFACEWARE

A collection of helpful XML node functions.

Source Code
-- xml module
-- http://help.interfaceware.com/code/details/xml-lua
-- Helpful extensions to core xml library in Iguana.

-- find or create first text element
function node.text(X)
   for i=1,#X do
      if X[i]:nodeType() == 'text' then
         return X[i]
      end
   end
   return X:append(xml.TEXT, '')
end

-- set or create+set a text element
-- NOTE: uses node.text() to create element if needed
function node.setText(X, T)
   X:text():setInner(T)
end

-- set or create+set an XML attribute
function node.setAttr(N, K, V)
   if N:nodeType() ~= 'element' then
      error('Must be an element')
   end
   if not N[K] or N[K]:nodeType() ~= 'attribute' then
      N:append(xml.ATTRIBUTE, K)
   end
   N[K] = V
   return N
end

-- find an XML element by name
function xml.findElement(X, Name)
   if X:nodeName() == Name then
      return X
   end
   for i = 1, #X do
      local Y = xml.findElement(X[i], Name)
      if Y then return Y end
   end
   return nil
end

-- append an XML element
function node.addElement(X, Name)
   return X:append(xml.ELEMENT, Name)
end

local node_setText = {
   Title="node.setText",
   Usage="node.setText(target, value)",
   SummaryLine="Sets the text in an XML TEXT element.",
   Desc=[[Sets the text in an XML TEXT element. This works with a simple text element, 
   or a "complex element" (one with sub-elements). If a text element does not exist it
   is appended to the parent element.
   ]],
   ParameterTable= false,
   Parameters={
      {target={Desc='Parent XML Element to set the text for <u>xml element</u>'}},
      {value={Desc='Text string value for the element <u>string</u>'}}, 
   },
   Examples={[[   node.setText(CD.title, 'Good Health Clinic Consultation Note')
   --> &lt;title&gt;Good Health Clinic Consultation Note&lt;/title&gt;

   -- In this example we append a text element to a complex element
   node.setText(GP.name, 'Append a text element')

   -- Result:      
   &lt;name&gt;
       &lt;given&gt;Ralph&lt;/given&gt;
       &lt;family&gt;Jones&lt;/family&gt;
       Append a text element  -- appended text element
   &lt;/name&gt;
   ]]},
   SeeAlso={
      {
         Title="xml.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/xml-lua"
      },
      {
         Title="XML Techniques in the Protocols repository",
         Link="http://help.interfaceware.com/v6/xml-channel"
      },
      {
         Title="Working with X12",
         Link="http://help.interfaceware.com/v6/working-with-x12"
      }
   }
}

help.set{input_function=node.setText, help_data=node_setText}

local node_setAttr = {
   Title="node.setAttr",
   Usage="node.setAttr(target, atribute, value)",
   SummaryLine="Sets the named attribute to a specified value.",
   Desc=[[Sets the named attribute to a specified value. If a the specified attribute does 
   not exist it is appended to the parent element. 
   ]],
   ParameterTable= false,
   Parameters={
      {target={Desc='Parent XML Element to set the attribute for <u>xml element</u>'}},
      {attribute={Desc='The name of the attribute to set <u>string</u>'}}, 
      {value={Desc='Text string value for the attribute <u>string</u>'}}, 
   },
   Returns={{Desc="The updated parent element <u>xml element</u>"}},
   Examples={[[   -- append an attribute to the "playingEntity"
   node.setAttr(PE, 'classCode', 'PLC')

   Result:   
   &lt;playingEntity classCode="PLC"&gt;                     -- appended attribute
      &lt;name&gt;Community Urgent Care Center&lt;/name&gt;
   &lt;/playingEntity&gt;
      
   -- append a another attribute
   node.setAttr(PE, 'another', 'attribute')
      
   Result:
   &lt;playingEntity classCode="PLC" another="attribute"&gt; -- another appended attribute
      &lt;name>Community Urgent Care Center&lt;/name&gt;
   &lt;/playingEntity&gt;
   ]]},
   SeeAlso={
      {
         Title="xml.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/xml-lua"
      },
      {
         Title="XML Techniques in the Protocols repository",
         Link="http://help.interfaceware.com/v6/xml-channel"
      },
      {
         Title="Working with X12",
         Link="http://help.interfaceware.com/v6/working-with-x12"
      }
   }
}

help.set{input_function=node.setAttr, help_data=node_setAttr}

local node_addElement = {
   Title="node.addElement",
   Usage="node.addElement{target, element)",
   SummaryLine="Appends an empty named element .",
   Desc=[[Appends an empty named element to the specified target (parent) element.]],
   Returns={Desc={"The appended element <u>xml element</u>"}},
   Parameters={
      {target={Desc='Parent XML Element to add the element to <u>xml element</u>'}},
      {element={Desc='The name of the element to append <u>string</u>'}}, 
   },
   Examples={[[   local P = node.addElement(birthplace, 'place')
      
   -- Result:      
   &lt;birthplace&gt;
      &lt;place&gt;   -- place element added
      &lt;/place&gt;
   &lt;/birthplace&gt;]]},
   SeeAlso={
      {
         Title="xml.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/xml-lua"
      },
      {
         Title="XML Techniques in the Protocols repository",
         Link="http://help.interfaceware.com/v6/xml-channel"
      },
      {
         Title="Working with X12",
         Link="http://help.interfaceware.com/v6/working-with-x12"
      }
   }
}

help.set{input_function=node.addElement, help_data=node_addElement}

local xml_findElement = {
   Title="xml.findElement",
   Usage="xml.findElement(target, element)",
   SummaryLine="Find the first element of the specified name in the target.",
   Desc=[[Find the first element of the specified name in the target. 
   <p>If the target is a tree, it will do a depth-first search of tree. 
   <p><strong>Note</strong>: If there are multiple elements with the same name
   this function will only find the first one.
   ]],
   Returns={{Desc="The first element found that matches the name specified <u>xml element</u>"}},
   Parameters={
      {target={Desc='Element to search within <u>xml element</u>'}},
      {element={Desc='The name of the element to search for <u>string</u>'}}, 
   },
   Examples={"xml.findElement(G,'guardianPerson')"},
   SeeAlso={
      {
         Title="xml.lua - in our code repository",
         Link="http://help.interfaceware.com/code/details/xml-lua"
      },
      {
         Title="XML Techniques in the Protocols repository",
         Link="http://help.interfaceware.com/v6/xml-channel"
      },
      {
         Title="Working with X12",
         Link="http://help.interfaceware.com/v6/working-with-x12"
      }
   }
}

help.set{input_function=xml.findElement, help_data=xml_findElement}
Description
A collection of helpful XML node functions.
Usage Details

This module helps resolve some common issues that arise when working with XML node trees:

  1. Use node.text() to resolve the “Index X is out of bounds” error caused by trying to read an empty XML TEXT element.
  2. Use node.setText() to resolve the “Index X is out of bounds” error caused by trying to set an empty XML TEXT element.
  3. Use node.setText() to set a TEXT element to a space, instead of using node.setInner() which ignores the space and sets it to empty.

For full usage details, please see the links below.

More Information
• Working with X12
Bookmark
  • Reviews
  • Related Listings
Filter
Sort by: Newest First
  • Oldest First
  • Rating
  • Helpfulness
Write a Review
Rating
Keyword
Filter
Sort by: Title
  • Newest First
  • Oldest First
  • Most Reviews
  • Highest Rated
Rating
iNTERFACEWARE
age.lua
Added by iNTERFACEWARE
Modules
This module calculates age from DOB, it returns years, months and partial years (i.e., 17, 3, 17.296272)
auth.lua
Added by iNTERFACEWARE
Modules
A module that does basic authentication for incoming web requests
batch.lua
Added by iNTERFACEWARE
Modules
A module to help processing batched HL7 messages
codemap.lua
Added by iNTERFACEWARE
Modules
This module is used to map one set of codes to another set of codes, or to validate code membership in a set
csv_parse.lua
Added by iNTERFACEWARE
Modules
A module for parsing well-formed CSV files.
custom_merge.lua
Added by iNTERFACEWARE
Modules
A customizable database merge method for Iguana 5.5.1 and up.
dateparse.lua
Added by iNTERFACEWARE
Modules
A fuzzy date/time parser that is very useful for automatically translating a wide variety of date/time formats.
dup.lua
Added by iNTERFACEWARE
Modules
Duplicate message filter.
edifact.lua
Added by iNTERFACEWARE
Modules
Convert EDI messages to HL7 format so you can process them like an HL7 message (and convert them back to EDI afterwards)
hl7.findSegment.lua
Added by iNTERFACEWARE
Modules
A utility for finding any HL7 segment in a parsed HL7 message node tree.
hl7.serialize.lua
Added by iNTERFACEWARE
Modules
Serializes an HL7 message using specified non-standard delimiters and/or escape characters
hl7.zsegment.lua
Added by iNTERFACEWARE
Modules
Generic Z segment parser. Parses Z segments without needing grammar definitions in the VMD file.
iguanaServer.lua
Added by iNTERFACEWARE
Modules
Provides programmatic access to various operations that can be performed on Iguana channels.
llp.lua
Added by iNTERFACEWARE
Modules
Allows you to use LLP connections from a Translator script
mime.lua
Added by iNTERFACEWARE
Modules
Sends MIME-encoded email attachments using the SMTP protocol. A wrapper around net.smtp.send.
resubmit.lua
Added by iNTERFACEWARE
Modules
Resubmit a logged message to an Iguana channel using the unique reference number (refmsgid).
retry.lua
Added by iNTERFACEWARE
Modules
A module for retrying operations which might periodically fail like database operations.
rtf.lua
Added by iNTERFACEWARE
Modules
A module for converting a RTF file to plain text.
scheduler.lua
Added by iNTERFACEWARE
Modules
Schedule jobs to run at a specified time of day, very useful for batch processing
scrub.lua
Added by iNTERFACEWARE
Modules
The “scrub” module given below redacts sensitive information from HL7 messages.
Showing 1 - 20 of 31 results
«12»

Topics

  • expandGetting Started
  • expandAdministration
    • expandInstallation
    • expandLicensing
    • expandUpgrades
    • expandDeployment
    • expandConfiguration Management
      • expandCustom Configuration
    • expandBackup and Restore
    • expandSecurity
      • expandHIPAA Compliance
    • expandTroubleshooting
  • expandDeveloping Interfaces
    • expandArchitecture
    • expandInterfaces
      • expandHL7
      • expandDatabase
        • expandConnect
      • expandWeb Services
      • expandCDA
      • expandX12
      • expandOther Interfaces
      • expandUtilities
    • expandRepositories
      • expandBuiltin Repositories
        • expandIguana Upgrade
        • expandIguana Tutorials
        • expandIguana Tools
        • expandIguana Protocols
        • expandIguana Files
        • expandIguana Date/Time
        • expandIguana Webservices
        • expandIguana Excel
      • expandRemote Repositories
      • expandCS Team Repositories
        • expandIguana Channels
    • expandSample Code
      • expandModules
      • expandUsing built-in functions
      • expandWorking with XML
    • expandLua Programming
    • expandPerformance
  • expandFAQs and TIPs
    • expandFrequently Asked Questions
      • expandInstalls and Upgrades
      • expandWeb Services
      • expandConfiguration
      • expandChannels
      • expandTranslator
      • expandOther
      • expandDatabase
      • expandAdministration
      • expandLogs
      • expandChameleon
    • expandTips
      • expandChannels
      • expandChameleon
      • expandWeb Services
      • expandSecurity
      • expandProgramming
      • expandOther
      • expandAdministration
  • expandReference
    • expandIguana Enterprise and Professional
    • expandProgram Settings
    • expandChannel Settings
    • expandDashboard
    • expandChannels
    • expandTranslator
    • expandLogs
      • expandLog Encryption
    • expandHTTP API
    • expandCDA API
    • expandError Messages
    • expandChameleon
    • expandIguana Change Log

Other Links

  • Training Center
  • News & Announcements
  • iNTERFACEWARE Blog
  • Older Documention (IGUANA v4 & Chameleon)
Copyright © iNTERFACEWARE Inc.