List of usage examples for javax.xml.parsers DocumentBuilderFactory setIgnoringElementContentWhitespace
public void setIgnoringElementContentWhitespace(boolean whitespace)
From source file:Main.java
public static Document load(String path) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(false);// www . j a v a2 s.c om factory.setIgnoringElementContentWhitespace(false); factory.setValidating(false); factory.setCoalescing(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(path); }
From source file:Main.java
public static Document load(File file) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(false);/*from w w w . j av a 2 s . c om*/ factory.setIgnoringElementContentWhitespace(false); factory.setValidating(false); factory.setCoalescing(true); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(file); }
From source file:Main.java
private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(false);/*from w ww . j av a 2s.c o m*/ factory.setIgnoringElementContentWhitespace(true); return factory.newDocumentBuilder(); }
From source file:Main.java
private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringComments(true);// ww w . j a v a2 s. c om dbf.setCoalescing(true); dbf.setIgnoringElementContentWhitespace(true); dbf.setValidating(false); return dbf.newDocumentBuilder(); }
From source file:Main.java
/** * // w ww . j a v a 2s . com */ public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setIgnoringElementContentWhitespace(true); factory.setIgnoringComments(true); factory.setCoalescing(true); factory.setNamespaceAware(false); return factory.newDocumentBuilder(); }
From source file:Main.java
public static Document blankDocument(String paramString) throws Exception { DocumentBuilderFactory localDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); localDocumentBuilderFactory.setIgnoringComments(false); localDocumentBuilderFactory.setIgnoringElementContentWhitespace(false); localDocumentBuilderFactory.setValidating(false); localDocumentBuilderFactory.setCoalescing(false); DocumentBuilder localDocumentBuilder = localDocumentBuilderFactory.newDocumentBuilder(); Document localDocument = localDocumentBuilder.newDocument(); Element localElement = localDocument.createElement(paramString); localDocument.appendChild(localElement); return localDocument; }
From source file:Main.java
public static Document loadString(String domContent) throws Exception { javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(false);//w w w. jav a 2s . c o m factory.setIgnoringElementContentWhitespace(false); factory.setValidating(false); factory.setCoalescing(false); DocumentBuilder builder = factory.newDocumentBuilder(); char[] chars = new char[domContent.length()]; domContent.getChars(0, domContent.length(), chars, 0); InputSource is = new InputSource(new CharArrayReader(chars)); return (builder.parse(is)); }
From source file:Main.java
public static synchronized DocumentBuilder getSyncDocumentBuilder(boolean namespaceAware, boolean coalescing, boolean ignoringElementContentWhitespace) throws ParserConfigurationException { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(namespaceAware); domFactory.setCoalescing(coalescing); domFactory.setIgnoringElementContentWhitespace(ignoringElementContentWhitespace); return domFactory.newDocumentBuilder(); }
From source file:Main.java
public static String extractValue(String xml, String xpathExpression) { String actual;/*from ww w. jav a 2 s.com*/ try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); byte[] bytes = xml.getBytes("UTF-8"); InputStream inputStream = new ByteArrayInputStream(bytes); Document doc = docBuilder.parse(inputStream); XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xpath = xPathFactory.newXPath(); actual = xpath.evaluate(xpathExpression, doc, XPathConstants.STRING).toString(); } catch (Exception e) { throw new RuntimeException(e); } return actual; }
From source file:Main.java
/** Read XML as DOM. *///from w w w .java 2s . co m public static Document readXml(InputStream is) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setIgnoringComments(false); dbf.setIgnoringElementContentWhitespace(true); //dbf.setCoalescing(true); //dbf.setExpandEntityReferences(true); DocumentBuilder db = null; db = dbf.newDocumentBuilder(); db.setEntityResolver(new NullResolver()); // db.setErrorHandler( new MyErrorHandler()); Document doc = db.parse(is); return doc; }