List of usage examples for javax.xml.parsers DocumentBuilderFactory setIgnoringElementContentWhitespace
public void setIgnoringElementContentWhitespace(boolean whitespace)
From source file:Main.java
public static Document parse(File file) throws IOException { try {/* ww w. j a v a 2 s . c o m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setCoalescing(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setNamespaceAware(true); DocumentBuilder parser = factory.newDocumentBuilder(); return parser.parse(file); } catch (ParserConfigurationException e) { throw new IOException(e); } catch (SAXException e) { throw new IOException(e); } }
From source file:Main.java
public static Document parse(InputStream is) throws IOException { try {//from w w w. j a va 2s . c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setCoalescing(true); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(true); factory.setNamespaceAware(true); DocumentBuilder parser = factory.newDocumentBuilder(); InputSource in = new InputSource(is); return parser.parse(in); } catch (ParserConfigurationException e) { throw new IOException(e); } catch (SAXException e) { throw new IOException(e); } }
From source file:com.synclio.hawk.TutorialRouteBuilder.java
private static DocumentBuilderFactory createDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from ww w . j a v a2 s . c om*/ factory.setIgnoringElementContentWhitespace(true); factory.setIgnoringComments(true); return factory; }
From source file:Main.java
/** * @param xmlStr//w w w. j a v a 2 s . c o m * @return the Document or null upon error. */ public static Document createDocumentFromXmlString(String xmlStr) { try { DocumentBuilderFactory docBuilderFactory; docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setIgnoringComments(true); docBuilderFactory.setIgnoringElementContentWhitespace(true); docBuilderFactory.setNamespaceAware(false); DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); ByteArrayInputStream bais = new ByteArrayInputStream(xmlStr.getBytes()); Document doc = builder.parse(bais); return doc; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Document parse(String xmlStr) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false);// w w w . j av a2s .co m factory.setNamespaceAware(false); factory.setIgnoringComments(true); factory.setIgnoringElementContentWhitespace(false); factory.setCoalescing(false); factory.setExpandEntityReferences(true); DocumentBuilder builder = factory.newDocumentBuilder(); ByteArrayInputStream inputStream = new ByteArrayInputStream(xmlStr.getBytes()); return builder.parse(inputStream); }
From source file:Main.java
/** * Returns a default DocumentBuilder instance or throws an * ExceptionInInitializerError if it can't be created. * * @return a default DocumentBuilder instance. */// ww w.j a va 2 s . co m public static DocumentBuilder getDocumentBuilder() throws Exception { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringComments(true); dbf.setCoalescing(true); dbf.setIgnoringElementContentWhitespace(true); dbf.setValidating(false); return dbf.newDocumentBuilder(); } catch (Exception exc) { throw new Exception(exc.getMessage()); } }
From source file:edu.harvard.i2b2.fhir.Utils.java
public static Document xmltoDOM(String xmlStr) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbFac = DocumentBuilderFactory.newInstance(); dbFac.setIgnoringElementContentWhitespace(true); DocumentBuilder db = dbFac.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlStr)); return db.parse(is); }
From source file:com.marklogic.hub.HubTestBase.java
protected static Document getXmlFromResource(String resourceName) throws IOException, ParserConfigurationException, SAXException { InputStream inputStream = HubTestBase.class.getClassLoader().getResourceAsStream(resourceName); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringElementContentWhitespace(true); factory.setNamespaceAware(true);/*ww w. j av a2 s .c o m*/ DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(inputStream); }
From source file:DomUtil.java
/** * Read XML as DOM.// w w w . ja va 2s . c o 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; }
From source file:Main.java
public static Document createDocument() { try {//from w ww. java 2 s . c om // Use JAXP to create a document builder DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setExpandEntityReferences(false); builderFactory.setValidating(false); builderFactory.setNamespaceAware(true); builderFactory.setIgnoringComments(true); builderFactory.setCoalescing(true); builderFactory.setIgnoringElementContentWhitespace(true); return builderFactory.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException errParser) { throw new RuntimeException("Error getting XML parser", errParser); } }