List of usage examples for javax.xml.parsers DocumentBuilderFactory newDocumentBuilder
public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException;
From source file:Main.java
License:asdf
public static void main(String args[]) throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); xmlDoc.setStrictErrorChecking(true); }
From source file:Main.java
License:asdf
public static void main(String args[]) throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); System.out.println(xmlDoc.getXmlVersion()); }
From source file:Main.java
License:asdf
public static void main(String args[]) throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); System.out.println(xmlDoc.getXmlStandalone()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder loader = factory.newDocumentBuilder(); Document document = loader.newDocument(); Element order = document.createElement("order"); document.appendChild(order);//from w w w.j a v a 2s . co m XMLSerializer serializer = new XMLSerializer(); serializer.setOutputCharStream(new java.io.FileWriter("order.xml")); serializer.serialize(document); }
From source file:Main.java
public static void main(String[] args) throws Exception { String xmlfile = "data.xml"; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(xmlfile); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); Element element = (Element) xpath.evaluate("/root/param[@name='name2']", doc, XPathConstants.NODE); System.out.println(element.getTextContent()); }
From source file:Main.java
public static void main(String argv[]) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new File("data.xml")); doc.getDocumentElement().normalize(); System.out.println("City: " + doc.getDocumentElement().getChildNodes().item(0).getFirstChild() .getChildNodes().item(0).getAttributes().getNamedItem("data").getNodeValue()); System.out.println("Postal Code: " + doc.getDocumentElement().getChildNodes().item(0).getFirstChild() .getChildNodes().item(1).getAttributes().getNamedItem("data").getNodeValue()); System.out.println("Date: " + doc.getDocumentElement().getChildNodes().item(0).getFirstChild() .getChildNodes().item(4).getAttributes().getNamedItem("data").getNodeValue()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder loader = factory.newDocumentBuilder(); Document document = loader.parse("sample.xml"); Element order = document.getDocumentElement(); DocumentRange ranges = (DocumentRange) document; Range range = ranges.createRange();//from ww w .j av a 2 s . com range.setStartBefore(order.getFirstChild()); range.setEndAfter(order.getLastChild()); range.deleteContents(); range.detach(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "<p>" + " <media type='audio' id='au008093' rights='aaa'>" + " <title>title</title>" + " this is a test." + "</p>"; InputStream is = new ByteArrayInputStream(s.getBytes()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document d = db.parse(is);//from w w w . j av a 2 s .c o m Node rootElement = d.getDocumentElement(); System.out.println(nodeToString(rootElement)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData()))); setAttribute(doc.getDocumentElement(), "attr", "new Vaue"); System.out.println(documentToString(doc)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData()))); edit(doc);/*from www . j a va 2s. c o m*/ System.out.println(documentToString(doc)); }