List of usage examples for javax.xml.parsers DocumentBuilderFactory newInstance
public static DocumentBuilderFactory newInstance()
From source file:Main.java
public static Document load(String filename) { Document document = null;/*from w ww. ja v a 2 s .c o m*/ try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(new File(filename)); document.normalize(); } catch (Exception ex) { ex.printStackTrace(); } return document; }
From source file:Main.java
public static String getValue(String xmlPath, String key) throws Exception { File file = new File(xmlPath); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(file); return doc.getElementsByTagName(key).item(0).getFirstChild().getNodeValue(); }
From source file:Main.java
public static Document getDocumentFromStream(InputStream is, boolean namespaceAware) { try {//from ww w.java 2s . c o m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(namespaceAware); DocumentBuilder builder = dbf.newDocumentBuilder(); Document ret = builder.parse(is); return ret; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Document stringToDoc(final String xml) throws Exception { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); final InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); }
From source file:Main.java
public static Document blankDocument(String paramString) throws Exception { DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); localDocumentBuilderFactory.setIgnoringComments(false); localDocumentBuilderFactory.setIgnoringElementContentWhitespace(false); localDocumentBuilderFactory.setValidating(false); localDocumentBuilderFactory.setCoalescing(false); DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder(); Document localDocument = localDocumentBuilder.newDocument(); Element localElement = localDocument.createElement(paramString); localDocument.appendChild(localElement); return localDocument; }
From source file:Main.java
public static Document createDocument() throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); docFactory.setNamespaceAware(true);/* w ww. j av a2 s . com*/ return docBuilder.newDocument(); }
From source file:Main.java
private static Document initializeXML(File xmlFile) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile); doc.getDocumentElement().normalize(); return doc;/* w ww . j a v a2s . c o m*/ }
From source file:Main.java
public static Document createDocument() throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.newDocument(); }
From source file:Main.java
public static Document convertStringToDocument(String xmlStr) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;/*ww w . j a v a2 s . c om*/ try { builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new StringReader(xmlStr))); return doc; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Document read(InputStream input) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {//from w ww . j a v a 2 s. co m DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(input); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } // SAXReader saxReader = new SAXReader(); // Document document; // try { // document = saxReader.read(input); // } // catch (DocumentException e) { // throw new RuntimeException(e.getMessage(), e); // } // return document; }