- Hlavní stránka
- Balíky
- Třídy
- Soubory

# src/cz/neubauer/tomas/hazardanalysis/model/XMLReader.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.model;
    00005
    00006 import java.io.IOException;
    00007
    00008 import javax.xml.namespace.QName;
    00009 import javax.xml.parsers.DocumentBuilder;
    00010 import javax.xml.parsers.DocumentBuilderFactory;
    00011 import javax.xml.parsers.ParserConfigurationException;
    00012 import javax.xml.xpath.XPath;
    00013 import javax.xml.xpath.XPathExpression;
    00014 import javax.xml.xpath.XPathExpressionException;
    00015 import javax.xml.xpath.XPathFactory;
    00016
    00017 import org.w3c.dom.Document;
    00018 import org.xml.sax.SAXException;
    00019
    00023 public class XMLReader {
    00024
    00036         public static Object readXML(String path, String xPath, QName returnType) {
    00037                 if (path == null) {
    00038                         return null;
    00039                 }
    00040                 Object retval = null;
    00041
    00042                 try {
    00043                         DocumentBuilderFactory domFactory = DocumentBuilderFactory
    00044                                         .newInstance();
    00045                         domFactory.setNamespaceAware(false);
    00046                         DocumentBuilder builder;
    00047
    00048                         builder = domFactory.newDocumentBuilder();
    00049
    00050                         Document doc = builder.parse(path);
    00051
    00052                         XPathFactory factory = XPathFactory.newInstance();
    00053                         XPath xpath = factory.newXPath();
    00054
    00055                         XPathExpression expr = xpath.compile(xPath);
    00056                         retval = expr.evaluate(doc, returnType);
    00057
    00058                 } catch (ParserConfigurationException e) {
    00059                         e.printStackTrace();
    00060                 } catch (XPathExpressionException e) {
    00061                         e.printStackTrace();
    00062                 } catch (SAXException e) {
    00063                         e.printStackTrace();
    00064                 } catch (IOException e) {
    00065                         e.printStackTrace();
    00066                 }
    00067                 return retval;
    00068         }
    00069 }