/** * Returns a semantic equivalent of a given XML-encoded message in a default format. * Attributes, comments, and processing instructions are not considered to change the * HL7 meaning of the message, and are removed in the standardized representation. */ public static String standardizeXML(String message) throws SAXException { try { Document doc = XMLUtils.parse(message); clean(doc.getDocumentElement()); return XMLUtils.serialize(doc, true); } catch (Exception e) { throw new RuntimeException("Exception while standardizing XML ", e); } }
/** * Returns a semantic equivalent of a given XML-encoded message in a default format. * Attributes, comments, and processing instructions are not considered to change the * HL7 meaning of the message, and are removed in the standardized representation. */ public static String standardizeXML(String message) throws SAXException { try { Document doc = XMLUtils.parse(message); clean(doc.getDocumentElement()); return XMLUtils.serialize(doc, true); } catch (Exception e) { throw new RuntimeException("Exception while standardizing XML ", 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); } }
/** * 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); } }