Mercurial > dive4elements > framework
comparison 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 |
comparison
equal
deleted
inserted
replaced
334:eb8dbfa7125d | 335:e7d3f74854fb |
---|---|
47 import org.apache.log4j.Logger; | 47 import org.apache.log4j.Logger; |
48 | 48 |
49 import org.w3c.dom.Attr; | 49 import org.w3c.dom.Attr; |
50 import org.w3c.dom.Document; | 50 import org.w3c.dom.Document; |
51 import org.w3c.dom.Element; | 51 import org.w3c.dom.Element; |
52 import org.w3c.dom.Node; | |
52 | 53 |
53 import org.xml.sax.SAXException; | 54 import org.xml.sax.SAXException; |
54 | 55 |
55 /** | 56 /** |
56 * Some helper functions to ease work with XML concering namespaces, XPATH | 57 * Some helper functions to ease work with XML concering namespaces, XPATH |
173 catch (ParserConfigurationException pce) { | 174 catch (ParserConfigurationException pce) { |
174 logger.error(pce.getLocalizedMessage(), pce); | 175 logger.error(pce.getLocalizedMessage(), pce); |
175 } | 176 } |
176 return null; | 177 return null; |
177 } | 178 } |
179 | |
180 | |
181 /** | |
182 * Create xml/string representation of element (nested in otherwise empty | |
183 * document). | |
184 * @param element element to inspect in string. | |
185 * @return string with xml representation of element. | |
186 */ | |
187 public final static String toString(Element element) { | |
188 Document doc = newDocument(); | |
189 doc.appendChild(doc.importNode(element,true)); | |
190 return toString(doc); | |
191 } | |
192 | |
193 | |
194 /** | |
195 * Creates xml/string representation of node (nested in otherwise empty | |
196 * document). | |
197 * @param element element to inspect in string. | |
198 * @return string with xml representation of element. | |
199 */ | |
200 public final static String toString(Node node) { | |
201 Document doc = newDocument(); | |
202 doc.appendChild(node); | |
203 return toString(doc); | |
204 } | |
205 | |
178 | 206 |
179 /** | 207 /** |
180 * Loads a XML document namespace aware from a file | 208 * Loads a XML document namespace aware from a file |
181 * @param file The file to load. | 209 * @param file The file to load. |
182 * @return the XML document or null if something went wrong | 210 * @return the XML document or null if something went wrong |