changeset 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 911c684c8a1c
children 824dd614e647
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java
diffstat 2 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Dec 15 15:47:16 2009 +0000
+++ b/ChangeLog	Wed Dec 16 08:08:56 2009 +0000
@@ -1,3 +1,9 @@
+2009-12-16	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java:
+	  Added static method parseDocument(File) to load document from
+	  file.
+
 2009-12-15  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	  Issue106
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java	Tue Dec 15 15:47:16 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java	Wed Dec 16 08:08:56 2009 +0000
@@ -4,6 +4,8 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Attr;
 
+import org.xml.sax.SAXException;
+
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import javax.xml.parsers.ParserConfigurationException;
@@ -18,6 +20,9 @@
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 
+import java.io.File;
+import java.io.IOException;
+
 /**
  *  @author Sascha L. Teichmann
  */
@@ -67,6 +72,25 @@
         return null;
     }
 
+    public static final Document parseDocument(File file) {
+        try {
+            return DocumentBuilderFactory
+                .newInstance()
+                .newDocumentBuilder()
+                .parse(file);
+        }
+        catch (ParserConfigurationException pce) {
+            logger.error(pce.getLocalizedMessage(), pce);
+        }
+        catch (SAXException se) {
+            logger.error(se.getLocalizedMessage(), se);
+        }
+        catch (IOException ioe) {
+            logger.error(ioe.getLocalizedMessage(), ioe);
+        }
+        return null;
+    }
+
     public static final XPath newXPath() {
         return newXPath(null);
     }

http://dive4elements.wald.intevation.org