List of usage examples for javax.xml.parsers DocumentBuilderFactory setNamespaceAware
public void setNamespaceAware(boolean awareness)
From source file:Main.java
public static Document createDocument() { try {// w w w . ja v a 2 s . c o m // 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); } }
From source file:net.bpelunit.framework.control.util.BPELUnitUtil.java
/** * Initializes the parser component. This is necessary to be able to deal with severe CLASSPATH * problems (i.e. no parser in CLASSPATH) in a predictable manner. * //from w w w .j a va 2s. co m * @throws ParserConfigurationException */ public static void initializeParsing() throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); BPELUnitUtil.fgDocumentBuilder = factory.newDocumentBuilder(); }
From source file:gov.hhs.fha.nhinc.lift.proxy.util.ProxyUtil.java
public static org.w3c.dom.Element marshal(Object obj) throws JAXBException { try {/*from ww w .j av a2s . c o m*/ Document doc = null; JAXBContext jc = JAXBContext.newInstance(obj.getClass()); Marshaller marshaller = jc.createMarshaller(); javax.xml.parsers.DocumentBuilderFactory dbf; dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); doc = dbf.newDocumentBuilder().newDocument(); marshaller.marshal(obj, doc); log.info("Marshal: " + doc.getNodeValue()); return doc.getDocumentElement(); } catch (ParserConfigurationException ex) { throw new JAXBException("Unable to create document: " + ex.getMessage()); } }
From source file:Main.java
public static synchronized DocumentBuilder getJaxpDocBuilderNNS() throws ParserConfigurationException { try {//from w w w . ja v a2s.co m System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.SaxParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance(); docBuildFactory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", new Boolean(false)); docBuildFactory.setNamespaceAware(false); docBuildFactory.setValidating(false); return docBuildFactory.newDocumentBuilder(); } catch (ParserConfigurationException pce) { throw new RuntimeException(pce.getMessage()); } }
From source file:org.xacml4j.saml.XACMLAuthzDecisionQueryEndpointTest.java
public static Document parse(String resourcePath) throws Exception { InputStream in = null;//from w w w .ja va 2 s .c o m try { in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath); assertThat(in, notNullValue()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); return dbf.newDocumentBuilder().parse(in); } finally { Closeables.closeQuietly(in); } }
From source file:com.mycila.xmltool.XMLDocumentBuilderFactory.java
public static DocumentBuilder newDocumentBuilder(boolean ignoreNamespaces) { try {//from w ww. j ava 2 s .c o m javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory .newInstance(); factory.setNamespaceAware(!ignoreNamespaces); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new XMLErrorHandler(true)); builder.setEntityResolver(CachedEntityResolver.instance); return builder; } catch (ParserConfigurationException e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:com.onespatial.jrc.tns.oml_to_rif.fixture.DomBasedUnitTest.java
/** * Run once, before any tests are run./* ww w .j ava2 s . c o m*/ * * @throws FactoryConfigurationError * if any errors occurred configuring the * {@link DocumentBuilderFactory} * @throws ParserConfigurationException * if any errors occurred creating a {@link DocumentBuilder} * @throws TransformerConfigurationException * if any errors occurred configuring the * {@link TransformerFactory} */ @BeforeClass public static void beforeAnyTest() throws ParserConfigurationException, FactoryConfigurationError, TransformerConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); builder = factory.newDocumentBuilder(); TransformerFactory tFactory = TransformerFactory.newInstance(); transformer = tFactory.newTransformer(); }
From source file:eu.optimis.sm.gui.server.XmlUtil.java
public static Document getDocument(String xml) { try {/*from w ww .j av a2 s . c o m*/ // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (SAXException e) { return null; } catch (ParserConfigurationException e) { return null; } catch (IOException e) { return null; } }
From source file:Main.java
public static DocumentBuilder getJaxpDocBuilder() { try {// ww w . j a v a 2s .c o m synchronized (jaxpLock) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.SaxParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance(); docBuildFactory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE); docBuildFactory.setNamespaceAware(true); docBuildFactory.setValidating(false); return docBuildFactory.newDocumentBuilder(); } } catch (ParserConfigurationException pce) { throw new RuntimeException(pce.getMessage()); } }
From source file:Utils.java
public static Document readXml(Reader is) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false);/*w w w . jav a 2 s. c o m*/ dbf.setIgnoringComments(false); dbf.setIgnoringElementContentWhitespace(true); dbf.setNamespaceAware(true); // dbf.setCoalescing(true); // dbf.setExpandEntityReferences(true); DocumentBuilder db = null; db = dbf.newDocumentBuilder(); db.setEntityResolver(new NullResolver()); // db.setErrorHandler( new MyErrorHandler()); InputSource ips = new InputSource(is); return db.parse(ips); }