comparison artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 62:76abf0c64d3b

Added XML utils method to load XML file from file. artifacts/trunk@438 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 16 Dec 2009 08:08:56 +0000
parents 4ae4dc99127d
children 8b72676698b5
comparison
equal deleted inserted replaced
61:911c684c8a1c 62:76abf0c64d3b
1 package de.intevation.artifactdatabase; 1 package de.intevation.artifactdatabase;
2 2
3 import org.w3c.dom.Document; 3 import org.w3c.dom.Document;
4 import org.w3c.dom.Element; 4 import org.w3c.dom.Element;
5 import org.w3c.dom.Attr; 5 import org.w3c.dom.Attr;
6
7 import org.xml.sax.SAXException;
6 8
7 import javax.xml.parsers.DocumentBuilderFactory; 9 import javax.xml.parsers.DocumentBuilderFactory;
8 10
9 import javax.xml.parsers.ParserConfigurationException; 11 import javax.xml.parsers.ParserConfigurationException;
10 12
15 import javax.xml.xpath.XPathExpressionException; 17 import javax.xml.xpath.XPathExpressionException;
16 import javax.xml.xpath.XPathConstants; 18 import javax.xml.xpath.XPathConstants;
17 19
18 import javax.xml.namespace.NamespaceContext; 20 import javax.xml.namespace.NamespaceContext;
19 import javax.xml.namespace.QName; 21 import javax.xml.namespace.QName;
22
23 import java.io.File;
24 import java.io.IOException;
20 25
21 /** 26 /**
22 * @author Sascha L. Teichmann 27 * @author Sascha L. Teichmann
23 */ 28 */
24 public final class XMLUtils 29 public final class XMLUtils
61 .newDocumentBuilder() 66 .newDocumentBuilder()
62 .newDocument(); 67 .newDocument();
63 } 68 }
64 catch (ParserConfigurationException pce) { 69 catch (ParserConfigurationException pce) {
65 logger.error(pce.getLocalizedMessage(), pce); 70 logger.error(pce.getLocalizedMessage(), pce);
71 }
72 return null;
73 }
74
75 public static final Document parseDocument(File file) {
76 try {
77 return DocumentBuilderFactory
78 .newInstance()
79 .newDocumentBuilder()
80 .parse(file);
81 }
82 catch (ParserConfigurationException pce) {
83 logger.error(pce.getLocalizedMessage(), pce);
84 }
85 catch (SAXException se) {
86 logger.error(se.getLocalizedMessage(), se);
87 }
88 catch (IOException ioe) {
89 logger.error(ioe.getLocalizedMessage(), ioe);
66 } 90 }
67 return null; 91 return null;
68 } 92 }
69 93
70 public static final XPath newXPath() { 94 public static final XPath newXPath() {

http://dive4elements.wald.intevation.org