List of usage examples for javax.xml.parsers DocumentBuilderFactory newDocumentBuilder
public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException;
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 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. j a v a 2 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 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 Document parse(String s) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new ErrorHandler() { @Override// w w w . j av a 2 s . c om public void warning(SAXParseException exception) throws SAXException { } @Override public void error(SAXParseException exception) throws SAXException { } @Override public void fatalError(SAXParseException exception) throws SAXException { } }); Document rv = builder.parse(new ByteArrayInputStream(s.getBytes("UTF-8"))); return rv; }
From source file:Main.java
public static Document newDocument() throws ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbf.newDocumentBuilder(); return builder.newDocument(); }
From source file:Main.java
public static org.w3c.dom.Document newDocument() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.newDocument(); }
From source file:Main.java
public static Document getDoc(InputStream in) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(in);/* w w w . ja va 2s .c om*/ return doc; }
From source file:Main.java
/** * createXmlDocumnet creates a new Document object using the JAXP API. * @return Document a DOM style Document object. * @throws ParserConfigurationException/* w w w .ja v a 2s . c o m*/ */ public static Document createXmlDocument() throws ParserConfigurationException { DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); DocumentBuilder db = fact.newDocumentBuilder(); Document doc = db.newDocument(); return (doc); }
From source file:Main.java
/** * Initializes {@link DocumentBuilder} from passed {@link InputStream} of * XML document's file/*from w w w .j a v a 2 s .co m*/ * * @param stream * @return {@link DocumentBuilder} initialized from {@link InputStream} * @throws ParserConfigurationException */ private static DocumentBuilder initDocumentBuilder(InputStream stream) throws ParserConfigurationException { DocumentBuilder builder; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); return builder; }
From source file:Main.java
public static Document getDocument() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(fileName); }