Class DefaultXMLParser
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:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultXMLParser(HapiContext context) DefaultXMLParser(ModelClassFactory theFactory) Creates a new instance of DefaultXMLParser -
Method Summary
Modifier and TypeMethodDescriptionencodeDocument(Message source) Creates an XML Document that corresponds to the given Message object.static XMLParserConvenience factory method which returns an instance that has aNoValidation validation context.static voidTest harnessprotected static StringmakeGroupElementName(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.voidParses a particular message and returns the encoded structureparseDocument(Document xmlMessage, String version) Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.Methods inherited from class ca.uhn.hl7v2.parser.XMLParser
assertNamespaceURI, doEncode, doEncode, doEncode, doEncode, doParse, doParseForSpecificPackage, encode, getAckID, getCriticalResponseData, getDefaultEncoding, getEncoding, getKeepAsOriginalNodes, getTextEncoding, getVersion, keepAsOriginal, parse, parse, parse, parse, parseLeaf, parseStringIntoDocument, removeWhitespace, setKeepAsOriginalNodes, setTextEncodingMethods inherited from class ca.uhn.hl7v2.parser.Parser
applySuperStructureName, assertVersionExists, encode, encode, getFactory, getMessageStructureForEvent, getParserConfiguration, getValidationContext, instantiateMessage, instantiateMessageInASpecificPackage, makeControlMSH, parse, parseForSpecificPackage, setParserConfiguration, setValidationContext, supportsEncoding, validVersionMethods inherited from class ca.uhn.hl7v2.HapiContextSupport
getHapiContext, setHapiContext
-
Constructor Details
-
DefaultXMLParser
public DefaultXMLParser() -
DefaultXMLParser
-
DefaultXMLParser
Creates a new instance of DefaultXMLParser- Parameters:
theFactory- custom factory to use for model class lookup
-
-
Method Details
-
encodeDocument
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:
encodeDocumentin classXMLParser- Parameters:
source- message- Returns:
- the DOM document object of the encoded message
- Throws:
HL7Exception
-
parseDocument
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:
- Create an instance of the Message type you are going to handle with your subclass of XMLParser
- Go through the given Document and find the Elements that represent the top level of each message segment.
- For each of these segments, call
parse(Segment segmentObject, Element segmentElement), providing the appropriate Segment from your Message object, and the corresponding Element.
- Specified by:
parseDocumentin classXMLParser- Parameters:
xmlMessage- DOM message object to be parsedversion- HL7 version- Throws:
HL7Exception- if the message is not correctly formatted.EncodingNotSupportedException- if the message encoded is not supported by this parser.
-
makeGroupElementName
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
Test harness -
parse
Parses a particular message and returns the encoded structure- Specified by:
parsein classParser- Parameters:
theMessage- The message to encodetheString- The string to parse- Throws:
HL7Exception- If there is a problem encoding
-
getInstanceWithNoValidation
Convenience factory method which returns an instance that has aNoValidation validation context.
-