List of usage examples for javax.xml.parsers DocumentBuilderFactory newDocumentBuilder
public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException;
From source file:Main.java
public static Element getElementFromXml(String xmltext) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); StringReader sr = new StringReader(xmltext); InputSource is = new InputSource(sr); Document document = db.parse(is); return document.getDocumentElement(); }
From source file:Main.java
@Nonnull public static Document newDomDocument() throws IOException { try {//from w w w . j ava2 s.co m DocumentBuilderFactory factory = newDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.newDocument(); } catch (ParserConfigurationException e) { throw new IOException("Can't create new DOM-document.", e); } }
From source file:Main.java
public static Document getXMLDOM(String currentFile) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(currentFile); }
From source file:Main.java
public static Document getXMLDOM(URL url) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(url.openStream()); }
From source file:Main.java
public static Document getdoc(String uri) throws Exception { uri = uri.replace(" ", "%20"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null;//from ww w . ja va2 s .com db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); doc = db.parse(new URL(uri).openStream()); if (doc == null || doc.getTextContent() == "") { throw new Exception(); } else return doc; }
From source file:Main.java
public static Document inputStream2Document(InputStream is) throws ParserConfigurationException, SAXException, IOException { Document document = null;/* w ww. j a v a 2s.c o m*/ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); document = builder.parse(is); return document; }
From source file:Main.java
public static Document getDocumentForString(String str) throws IOException, SAXException, ParserConfigurationException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); return dbFactory.newDocumentBuilder().parse(new ByteArrayInputStream(str.getBytes())); }
From source file:Main.java
/** * @param path/*from ww w. j a v a2 s . c om*/ * @return * @throws FileNotFoundException * @throws SAXException * @throws IOException * @throws ParserConfigurationException */ public static Document parseXMLDom(String path) throws FileNotFoundException, SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder.parse(new FileInputStream(path)); }
From source file:Main.java
/** * Return he dom root element of an xml file * @param filePathInClassPath the file path relative to the classpath * @return the root element/*www. j a v a 2 s. co m*/ * @throws ParserConfigurationException * @throws IOException * @throws SAXException */ public static Element getRootElementFromFileInClasspath(String filePathInClassPath) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements Document doc = docBuilder.parse(new ClassPathResource(filePathInClassPath).getInputStream()); return doc.getDocumentElement(); }
From source file:Main.java
private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); return domFactory.newDocumentBuilder(); }