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.
for configuration options which may affect parser encoding and decoding behaviour
Constructor and Description |
---|
DefaultXMLParser() |
DefaultXMLParser(HapiContext context) |
DefaultXMLParser(ModelClassFactory theFactory)
Creates a new instance of DefaultXMLParser
|
Modifier and Type | Method and Description |
---|---|
Document |
encodeDocument(Message source)
Creates an XML Document that corresponds to the given Message object.
|
static XMLParser |
getInstanceWithNoValidation()
Convenience factory method which returns an instance that has a
NoValidation validation context . |
static void |
main(String[] args)
Test harness
|
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.
|
void |
parse(Message theMessage,
String theString)
Parses a particular message and returns the encoded structure
|
Message |
parseDocument(Document xmlMessage,
String version)
Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.
|
assertNamespaceURI, doEncode, doEncode, doEncode, doEncode, doParse, doParseForSpecificPackage, encode, getAckID, getCriticalResponseData, getDefaultEncoding, getEncoding, getKeepAsOriginalNodes, getTextEncoding, getVersion, keepAsOriginal, parse, parse, parse, parse, parseLeaf, parseStringIntoDocument, removeWhitespace, setKeepAsOriginalNodes, setTextEncoding
applySuperStructureName, assertVersionExists, encode, encode, getFactory, getMessageStructureForEvent, getParserConfiguration, getValidationContext, instantiateMessage, instantiateMessageInASpecificPackage, makeControlMSH, parse, parseForSpecificPackage, setParserConfiguration, setValidationContext, supportsEncoding, validVersion
getHapiContext, setHapiContext
public DefaultXMLParser()
public DefaultXMLParser(HapiContext context)
public DefaultXMLParser(ModelClassFactory theFactory)
theFactory
- custom factory to use for model class lookuppublic 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.
encodeDocument
in class XMLParser
source
- messageHL7Exception
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:
parse(Segment segmentObject, Element segmentElement)
,
providing the appropriate Segment from your Message object, and the corresponding Element.parseDocument
in class XMLParser
xmlMessage
- DOM message object to be parsedversion
- HL7 versionHL7Exception
- if the message is not correctly formatted.EncodingNotSupportedException
- if the message encoded
is not supported by this parser.protected static String makeGroupElementName(String messageName, String className)
public void parse(Message theMessage, String theString) throws HL7Exception
parse
in class Parser
theMessage
- The message to encodetheString
- The string to parseHL7Exception
- If there is a problem encodingpublic static XMLParser getInstanceWithNoValidation()
NoValidation validation context
.Copyright © 2001–2017 University Health Network. All rights reserved.