Sidebar

Creating XML Templates

0 votes
149 views
asked Aug 22, 2022 by randy-c-3449 (200 points)

I want to create an XML template from a sample XML file.  I have two parts to my question.

1.  I found this in the KB, 

The second way and for more complex XML messages it is often easier to create a template representing the new XML message which is saved as a System Variable and then adding Node Tags in the template that reference the HL7 fields.

Example Template:

<patient id="{PID-2}" mrn="{PID-3}" timestamp="{SYSTEM_DATE[yyyy-MM-dd hh:mm:ss]}">
  <demographics>
    <nameGiven>{PID-5.2}</nameGiven>
    <nameFirst>{PID-5.1}</nameFirst>
    <birthDate>{PID-7}</birthDate>
    <ssn>{PID-19}</ssn>
  </demographics>
</patient>

My first question for this is:  Should the labels be in quotes or not.  The first line has them in quoted, the remainder are not.

My second question is do you need to replace all the values in the XML document with a replacement text using the curly braces.

Thank you!!

1 Answer

0 votes

The double-quotes are used for XML attribute values, which exist within the XML tag.  Consider this XML element:

<book category="fiction">Book Title</book>

The XML attribute for this is category, which has a value of "fiction".  Attributes will usually be in double-quotes.  However, in the above example, Book Title is the text within an XML element, not the attribute value.  These generally are not double-quoted.  Here is a good resource on the different parts of an XML message: https://www.w3schools.com/xml/xml_elements.asp

As to your second question, you do not need to replace all values with node tags (items within curly braces); if there are static elements within your XML that never change from message to message, you can hard-code those values by just typing them into your template.

answered Aug 22, 2022 by jon-t-7005 (7,590 points)
...