List of usage examples for javax.xml.parsers DocumentBuilder parse
public abstract Document parse(InputSource is) throws SAXException, IOException;
From source file:Main.java
public static Document createDocument(InputStream inputStream) throws ParserConfigurationException, IOException, SAXException { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); return dBuilder.parse(inputStream); }
From source file:Main.java
public static Document parse(InputStream fStream) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.parse(fStream); }
From source file:Main.java
public static Document getDocFromBuffer(byte[] buf) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);//from w ww . ja v a 2s . c o m DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(buf)); return doc; }
From source file:Main.java
public static Document getDocument(File file) throws Throwable { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(file); return doc;// ww w. j a va 2s . c o m }
From source file:Main.java
public static Document getDocument(String xmlDocument) { try {// w ww . j a v a2s.c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xmlDocument.getBytes("UTF-8"))); } catch (Exception e) { throw new RuntimeException("Error parsing XML document", e); } }
From source file:Main.java
public static Document stringToDOM(String xmlString) { try {//from w w w . ja v a 2 s.co m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(xmlString))); } catch (Throwable t) { throw new RuntimeException("Error while building document"); } }
From source file:Main.java
public static Document fileToDOM(File file) { try {/*from www .ja va2 s.c o m*/ DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); return docBuilder.parse(file); } catch (Throwable t) { return null; } }
From source file:Main.java
public static Document loadFromFile(File file) throws IllegalAccessException, ParserConfigurationException, SAXException, IOException { if (!file.exists()) { throw new IllegalAccessException("File is not exists: " + file.getAbsolutePath()); }/*from www . ja v a2 s . c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(file); }
From source file:Main.java
public static Document load(String src) throws IOException, SAXException, ParserConfigurationException { Document doc = null;//from w ww. j a v a2 s .c o m InputSource is = new InputSource(new StringReader(src)); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder docBuilder = factory.newDocumentBuilder(); doc = docBuilder.parse(is); return doc; }
From source file:Main.java
public static Document getDocument(InputSource source) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(source); return doc;/*from w ww . j a v a 2 s . c o m*/ }