changeset 335:e7d3f74854fb

Added XMLUtils functions helping to debug parts of xml documents. artifacts/trunk@2815 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 23 Sep 2011 08:29:48 +0000
parents eb8dbfa7125d
children 2c968defd878
files ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java
diffstat 2 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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	<felix.wolfsteller@intevation.de>
+
+	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 <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.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.

http://dive4elements.wald.intevation.org