List of usage examples for javax.xml.parsers DocumentBuilderFactory newDocumentBuilder
public abstract DocumentBuilder newDocumentBuilder() throws ParserConfigurationException;
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()))); Element root = doc.getDocumentElement(); System.out.println(root);//from w w w.j a v a 2 s .c om }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(new File("input.xml")); NodeList nodeList = document.getElementsByTagName("Item"); for (int x = 0, size = nodeList.getLength(); x < size; x++) { System.out.println(nodeList.item(x).getAttributes().getNamedItem("name").getNodeValue()); }/*w w w . ja v a 2 s. com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(new File("yourFile.xml")); NodeList nodeList = document.getElementsByTagName("message"); for (int x = 0, size = nodeList.getLength(); x < size; x++) { System.out.println(nodeList.item(x).getAttributes().getNamedItem("to").getNodeValue()); }//w w w.ja v a 2 s . c om }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document xml = db.parse("input.xml"); XPathFactory xpf = XPathFactory.newInstance(); XPath xpath = xpf.newXPath(); String health = (String) xpath.evaluate("/game/health", xml, XPathConstants.STRING); System.out.println(health);// w w w . j a va 2s.c o m }
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()))); Element root = doc.getDocumentElement(); EntityReference eref = (EntityReference) root.getFirstChild(); }
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()))); NodeList list = doc.getElementsByTagName("*"); for (int i = 0; i < list.getLength(); i++) { Element element = (Element) list.item(i); System.out.println(element); }/*from www.ja v a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData()))); Element e = document.getDocumentElement(); System.out.println(e);/*w ww .j a v a2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder domBuilder = domFactory.newDocumentBuilder(); domBuilder.parse(args[0]);/*from ww w. j a v a 2 s .co m*/ System.out.println("'" + args[0] + "' is well-formed."); }
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 tree = document.getDocumentElement(); }
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 root = document.createElement("order"); document.appendChild(root);//from ww w. j a v a 2s .com }