...
Info |
---|
The default xml node and xml module provide limited functionalities to either parse or create XML node. In additional to https://help.interfaceware.com/v6/xml-channel. The XMLUtils.lua module extends further to the following capabilities: |
XMLUtils.lua
Expand | |||||
---|---|---|---|---|---|
| |||||
|
How to use XMLUtil.lua
Import the above XMLUtils.lua into your translator, parse an xml, and call the following extended xml functions below:
Node.select()
USAGE
Select child node from the root XML node based on the XML path. Unlike traditional xml node drill down with nil validation, you can easily use select function to find the sub child of xml node.
REQUIRED PARAMETERS
...
path: xml child node path
required: If 'required' is false and 'thisNode' is nil, the function returns nothing and exitstrue, the path must be exist otherwise throw “
required path not found
“ error.
RETURNS
The child node tree
...
Select child node from the root XML node based on the XML path.
REQUIRED PARAMETERS
XMLNode: the root of XML node
path: xml child node path
required: If 'required' is false and 'thisNode' is nil, the function returns nothing and exits.
...
Code Block |
---|
local patientXML = recordXMLchargeTransaction:selectnumber("chargeTransaction/patient", truebatchId") .. '-' .. chargeTransaction:number("syncId") |
Node.text()
USAGE
Select child node from Keep the root XML node based on XML element but empty the XML pathelement Text value
REQUIRED PARAMETERS
...
path: xml child node path
required: If 'required' is false and 'thisNode' is nil, the function returns nothing and exits.
...
The child node tree
SAMPLE CODE
Code Block |
---|
local patientXML PID[3][1] = recordXMLpatient:selecttext("chargeTransaction/patient", truemedicalRecordNumber") |
Node.children()
USAGE
Select child node from the root XML node based on the XML path
...
Code Block |
---|
local patientXML = recordXML:select("chargeTransaction/patient", true) |
Node.firstChild()
USAGE
Select child node from the root XML node based on the XML pathSearch for the first XML element that meets to criteria passed into the function.
REQUIRED PARAMETERS
XMLNodeElement Name: The name of the root of XML nodeelement.
path: xml child node path
required: If 'required' is false and 'thisNode' is nil, the function returns nothing and exitsAttribute Name: The attribute name that you want to be found. Make sure to include the “@” prefix.
Attribute Value: The attribute value attached to the attribute name to be found.
RETURNS
The child node treefirst match for the XML element.
SAMPLE CODE
Code Block |
---|
local patientXMLfirstElement = recordXMLXMLRecord:selectfirstChild("chargeTransaction/patient"Element", "@AttributeName", true"AttributeValue") |
Node.removeText()
USAGE
Select child node from Keep the root XML node based on XML element but empty the XML pathelement Text value
REQUIRED PARAMETERS
XMLNode: the root of XML node
path: xml child node path
required: If 'required' is false and 'thisNode' is nil, the function returns nothing and exits.None
RETURNS
The child node treeEmpty
SAMPLE CODE
Code Block |
---|
local patientXML = recordXML:select("chargeTransaction/patient", truerecordXML.element:removeText() |