diff options
author | peter.danner <peter.danner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-07-27 09:31:59 +0000 |
---|---|---|
committer | peter.danner <peter.danner@d688527b-c9ab-4aba-bd8d-4036d912da1d> | 2007-07-27 09:31:59 +0000 |
commit | db86329d1cec19bcd98afe58c2810951c87e12b2 (patch) | |
tree | fdc992fa7ee47fe787bbda7574b13984df50fb9e /common/src/at/gv/egovernment | |
parent | 6b7df32316881105833eaff57cb9353de8761703 (diff) | |
download | moa-id-spss-db86329d1cec19bcd98afe58c2810951c87e12b2.tar.gz moa-id-spss-db86329d1cec19bcd98afe58c2810951c87e12b2.tar.bz2 moa-id-spss-db86329d1cec19bcd98afe58c2810951c87e12b2.zip |
Extended serializing with the ability to omit the xml declaration
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@852 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'common/src/at/gv/egovernment')
-rw-r--r-- | common/src/at/gv/egovernment/moa/util/DOMUtils.java | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/common/src/at/gv/egovernment/moa/util/DOMUtils.java b/common/src/at/gv/egovernment/moa/util/DOMUtils.java index f94c8f6ff..d2e5e2195 100644 --- a/common/src/at/gv/egovernment/moa/util/DOMUtils.java +++ b/common/src/at/gv/egovernment/moa/util/DOMUtils.java @@ -443,7 +443,26 @@ public class DOMUtils { */ public static String serializeNode(Node node) throws TransformerException, IOException { - return new String(serializeNode(node, "UTF-8"), "UTF-8"); + return new String(serializeNode(node, "UTF-8", false), "UTF-8"); + } + + + /** + * Serialize the given DOM node. + * + * The node will be serialized using the UTF-8 encoding. + * + * @param node The node to serialize. + * @param omitXmlDeclaration The boolean value for omitting the XML Declaration. + * @return String The <code>String</code> representation of the given DOM + * node. + * @throws TransformerException An error occurred transforming the + * node to a <code>String</code>. + * @throws IOException An IO error occurred writing the node to a byte array. + */ + public static String serializeNode(Node node, boolean omitXmlDeclaration) + throws TransformerException, IOException { + return new String(serializeNode(node, "UTF-8", omitXmlDeclaration), "UTF-8"); } /** @@ -458,6 +477,23 @@ public class DOMUtils { * @throws IOException An IO error occurred writing the node to a byte array. */ public static byte[] serializeNode(Node node, String xmlEncoding) + throws TransformerException, IOException { + return serializeNode(node, xmlEncoding, false); + } + + /** + * Serialize the given DOM node to a byte array. + * + * @param node The node to serialize. + * @param xmlEncoding The XML encoding to use. + * @param omitXmlDeclaration The boolean value for omitting the XML Declaration. + * @return The serialized node, as a byte array. Using a compatible encoding + * this can easily be converted into a <code>String</code>. + * @throws TransformerException An error occurred transforming the node to a + * byte array. + * @throws IOException An IO error occurred writing the node to a byte array. + */ + public static byte[] serializeNode(Node node, String xmlEncoding, boolean omitDeclaration) throws TransformerException, IOException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); @@ -466,6 +502,8 @@ public class DOMUtils { transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, xmlEncoding); + String omit = omitDeclaration ? "yes" : "no"; + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omit); transformer.transform(new DOMSource(node), new StreamResult(bos)); bos.flush(); |