Class DefaultXMLParser


public class DefaultXMLParser extends XMLParser

A default XMLParser. This class assigns segment elements (in an XML-encoded message) to Segment objects (in a Message object) using the name of a segment and the names of any groups in which the segment is nested. The names of group classes must correspond to the names of group elements (they must be identical except that a dot in the element name, following the message name, is replaced with an underscore, in order to consitute a valid class name).

At the time of writing, the group names in the XML spec are changing. Many of the group names have been automatically generated based on the group contents. However, these automatic names are gradually being replaced with manually assigned names. This process is expected to be complete by November 2002. As a result, mismatches are likely. Messages could be transformed prior to parsing (using XSLT) as a work-around. Alternatively the group class names could be changed to reflect updates in the XML spec. Ultimately, HAPI group classes will be changed to correspond with the official group names, once these are all assigned.

Author:
Bryan Tripp
See Also:
  • Constructor Details

  • Method Details

    • encodeDocument

      public Document encodeDocument(Message source) throws HL7Exception

      Creates an XML Document that corresponds to the given Message object.

      If you are implementing this method, you should create an XML Document, and insert XML Elements into it that correspond to the groups and segments that belong to the message type that your subclass of XMLParser supports. Then, for each segment in the message, call the method encode(Segment segmentObject, Element segmentElement) using the Element for that segment and the corresponding Segment object from the given Message.

      Specified by:
      encodeDocument in class XMLParser
      Parameters:
      source - message
      Returns:
      the DOM document object of the encoded message
      Throws:
      HL7Exception
    • parseDocument

      public Message parseDocument(Document xmlMessage, String version) throws HL7Exception

      Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.

      The easiest way to implement this method for a particular message structure is as follows:

      1. Create an instance of the Message type you are going to handle with your subclass of XMLParser
      2. Go through the given Document and find the Elements that represent the top level of each message segment.
      3. For each of these segments, call parse(Segment segmentObject, Element segmentElement), providing the appropriate Segment from your Message object, and the corresponding Element.
      At the end of this process, your Message object should be populated with data from the XML Document.

      Specified by:
      parseDocument in class XMLParser
      Parameters:
      xmlMessage - DOM message object to be parsed
      version - HL7 version
      Throws:
      HL7Exception - if the message is not correctly formatted.
      EncodingNotSupportedException - if the message encoded is not supported by this parser.
    • makeGroupElementName

      protected static String makeGroupElementName(String messageName, String className)
      Given the name of a message and a Group class, returns the corresponding group element name in an XML-encoded message. This is the message name and group name separated by a dot. For example, ADT_A01.INSURANCE. If it looks like a segment name (i.e. has 3 characters), no change is made.
    • main

      public static void main(String[] args)
      Test harness
    • parse

      public void parse(Message theMessage, String theString) throws HL7Exception
      Parses a particular message and returns the encoded structure
      Specified by:
      parse in class Parser
      Parameters:
      theMessage - The message to encode
      theString - The string to parse
      Throws:
      HL7Exception - If there is a problem encoding
    • getInstanceWithNoValidation

      Convenience factory method which returns an instance that has a NoValidation validation context.