List of usage examples for javax.xml.parsers DocumentBuilder parse
public abstract Document parse(InputSource is) throws SAXException, IOException;
From source file:Main.java
private static Element getNewstudent() throws Exception { DocumentBuilder builder = dbFactory.newDocumentBuilder(); Document newstudent = builder.parse(new StringBufferInputStream(studentData)); Element student = newstudent.getDocumentElement(); return student; }
From source file:Main.java
public static Document buildXmlDocument(InputStream stream) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(stream); }
From source file:Main.java
public static org.w3c.dom.Document readXML(String xmlString) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/* w w w. ja va 2 s . c o m*/ DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xmlString.getBytes())); }
From source file:Main.java
public static void sendXml(String result, int operationN) throws Exception { String filepath = "file.xml"; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(filepath); Node tonode = doc.getElementsByTagName("command").item(0); Element res = doc.createElement("result"); res.setTextContent(result);// w w w. ja v a2 s . c o m tonode.appendChild(res); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result1 = new StreamResult(new File("file2.xml")); StreamResult result3 = new StreamResult(System.out); transformer.transform(source, result1); }
From source file:Main.java
public static Document parseToDom(String content) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(false);/* w w w. j av a 2 s. c o m*/ DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(content.getBytes())); }
From source file:Main.java
public static Document getDocument() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(fileName); }
From source file:Main.java
private static Document readXmlDocument(File xmlFile) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(xmlFile); return document; }
From source file:Main.java
public static Document getDocument() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(filename); }
From source file:Main.java
public static Document fromXML(String xml) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from w w w.j a v a2 s .co m*/ factory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8"))); }
From source file:Main.java
public static Document loadDocument(String file) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(file); }