Set the value of a node
Verified
Added by iNTERFACEWARE
Use node.setNodeValue() to set the value of a leaf node, works for all node types
Source Code
local Msg = hl7.message{vmd='demo.vmd', name='ADT'} -- NO BENEFIT: set the Time in the MSH segment Msg.MSH[7][1] = os.date('%Y%m%H%m') -- works: assigns value to the child node Msg.MSH[7][1]:setNodeValue(os.date('%Y%m%H%m')) -- works: set the node value -- BENEFIT: if you decide to use a variable local MsgTime = Msg.MSH[7][1] MsgTime:setNodeValue(os.date('%Y%m%H%m')) -- works: set the node value MsgTime = os.date('%Y%m%H%m') -- fails: assigns the date to the variable (try it)
Description
Use node.setNodeValue() to set the value of a leaf node, works for all node types
Usage Details
Use node.setNodeValue()
to set the value of a leaf node. Often assignment works instead (and is more succinct), however there are occasions when using node.setNodeValue()
is useful, for example if you place a node into a variable (see the sample code).
Note: The node.setNodeValue()
function works with all types of node trees.
How to use the snippet:
- Paste the code into your script
More Information
Added by iNTERFACEWARE
Code to connect to commonly used databases (connecting to other databases is very similar).
Added by iNTERFACEWARE
How to parse an HL7 message and create an HL7 output message
Added by iNTERFACEWARE
Use pcall() to trap errors by calling a function in protected mode (use to prevent a channel from stopping on "innocent" errors).
Added by iNTERFACEWARE
Use the error() function to raise an error and write it to the logs
Added by iNTERFACEWARE
How to create Error, Warning, Informational, and Debug log entries
Added by iNTERFACEWARE
How to open and read a file from disk, either one line at a time, or read the whole file at once
Added by iNTERFACEWARE
How to convert numbers and node trees to a to string representation, and how to convert a numeric strings to numbers
Added by iNTERFACEWARE
How to parse an XML message using xml.parse()
Added by iNTERFACEWARE
Using date and time functions with some formatting examples
Added by iNTERFACEWARE
Execute programs and batch files, you can also load results from a directory listing etc.
Added by iNTERFACEWARE
Convert characters to/from numeric codes, the codes will vary depending on the code page settings
Added by iNTERFACEWARE
Find the position of the first instance of a string (pattern) within a string, returns the start and end indices
Added by iNTERFACEWARE
Use string.gsub() to find and replace one or more instances of text within a string
Added by iNTERFACEWARE
Using # or string.len() to find the length of a string, the result is the same
Added by iNTERFACEWARE
Convert a string to upper case with string.upper(), or lower case with string.lower()
Added by iNTERFACEWARE
Use the string.split() function to split a string into parts separated by a specified delimiter
Added by iNTERFACEWARE
Use string.sub() to return part of a string, by specifying the start and end positions
Added by iNTERFACEWARE
Use conn:query() to select data from a table in a database
Added by iNTERFACEWARE
Use conn:execute() to insert data into a database table
Added by iNTERFACEWARE
Use conn:execute() to update a database table