/** * Formats a Message object into an HL7 message string using this parser's default encoding (XML * encoding). This method calls the abstract method <code>encodeDocument(...)</code> in order to * obtain XML Document object representation of the Message, then serializes it to a String. * * @throws HL7Exception if the data fields in the message do not permit encoding (e.g. required * fields are null) */ protected String doEncode(Message source) throws HL7Exception { if (source instanceof GenericMessage) { throw new HL7Exception( "Can't XML-encode a GenericMessage. Message must have a recognized structure."); } Document doc = encodeDocument(source); // Element documentElement = doc.getDocumentElement(); // if (!documentElement.hasAttribute("xmlns")) // documentElement.setAttribute("xmlns", "urn:hl7-org:v2xml"); try { return XMLUtils.serialize(doc, getParserConfiguration().isPrettyPrintWhenEncodingXml()); } catch (Exception e) { throw new HL7Exception("Exception serializing XML document to string", e); } }
/** * Formats a Message object into an HL7 message string using this parser's default encoding (XML * encoding). This method calls the abstract method <code>encodeDocument(...)</code> in order to * obtain XML Document object representation of the Message, then serializes it to a String. * * @throws HL7Exception if the data fields in the message do not permit encoding (e.g. required * fields are null) */ protected String doEncode(Message source) throws HL7Exception { if (source instanceof GenericMessage) { throw new HL7Exception( "Can't XML-encode a GenericMessage. Message must have a recognized structure."); } Document doc = encodeDocument(source); // Element documentElement = doc.getDocumentElement(); // if (!documentElement.hasAttribute("xmlns")) // documentElement.setAttribute("xmlns", "urn:hl7-org:v2xml"); try { return XMLUtils.serialize(doc, getParserConfiguration().isPrettyPrintWhenEncodingXml()); } catch (Exception e) { throw new HL7Exception("Exception serializing XML document to string", e); } }