List of usage examples for javax.xml.parsers DocumentBuilder parse
public abstract Document parse(InputSource is) throws SAXException, IOException;
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.normalizeDocument();//w w w. j a va 2 s . c om }
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.getXmlEncoding()); }
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))); DocumentFragment frag = xmlDoc.createDocumentFragment(); }
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.setDocumentURI("http://java2s.com"); }
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.parse("sample.xml"); Element purchaseOrder = document.getDocumentElement(); printElement(purchaseOrder, ""); }
From source file:Main.java
public static void main(String[] args) throws Exception { XPath xPath = XPathFactory.newInstance().newXPath(); FileInputStream file = new FileInputStream(new File("c:/data.xml")); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document xmlDocument = builder.parse(file); XPathExpression expr = xPath.compile("//project/*"); NodeList list = (NodeList) expr.evaluate(xmlDocument, XPathConstants.NODESET); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); System.out.println(node.getNodeName() + "=" + node.getTextContent()); }/* www. j a va 2 s .com*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true);// ww w . j a v a 2s. c om DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dDoc = builder.parse("c:\\file.xml"); XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new UniversalNamespaceResolver(dDoc)); String query = "//rss/channel/yweather:location/@city"; XPathExpression expr = xPath.compile(query); Object result = expr.evaluate(dDoc, XPathConstants.STRING); System.out.println(result); }