# HG changeset patch # User Felix Wolfsteller # Date 1316766588 0 # Node ID e7d3f74854fb533f0095994ac4687f5598452808 # Parent eb8dbfa7125df50092d55e5e295202d546301011 Added XMLUtils functions helping to debug parts of xml documents. artifacts/trunk@2815 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r eb8dbfa7125d -r e7d3f74854fb ChangeLog --- a/ChangeLog Thu Sep 22 15:32:54 2011 +0000 +++ b/ChangeLog Fri Sep 23 08:29:48 2011 +0000 @@ -1,3 +1,11 @@ +2011-09-23 Felix Wolfsteller + + Added XMLUtils functions helping to debug parts of xml documents. + + * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java: + (toString(Node), toString(Element): New functions returning + xml/string representations of parts of documents. + 2011-09-22 Ingo Weinzierl * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: diff -r eb8dbfa7125d -r e7d3f74854fb artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java --- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java Thu Sep 22 15:32:54 2011 +0000 +++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java Fri Sep 23 08:29:48 2011 +0000 @@ -49,6 +49,7 @@ import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.xml.sax.SAXException; @@ -176,6 +177,33 @@ return null; } + + /** + * Create xml/string representation of element (nested in otherwise empty + * document). + * @param element element to inspect in string. + * @return string with xml representation of element. + */ + public final static String toString(Element element) { + Document doc = newDocument(); + doc.appendChild(doc.importNode(element,true)); + return toString(doc); + } + + + /** + * Creates xml/string representation of node (nested in otherwise empty + * document). + * @param element element to inspect in string. + * @return string with xml representation of element. + */ + public final static String toString(Node node) { + Document doc = newDocument(); + doc.appendChild(node); + return toString(doc); + } + + /** * Loads a XML document namespace aware from a file * @param file The file to load.