diff artifacts-common/src/main/java/de/intevation/artifacts/common/utils/XMLUtils.java @ 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 1d3607ceb9fa
children 2c968defd878
line wrap: on
line diff
--- 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