Java 8 DocumentBuilderFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DocumentBuilderFactory class.

This code example shows how to use the following methods: setCoalescing, setExpandEntityReferences, setIgnoringComments, setIgnoringElementContentWhitespace, setNamespaceAware
        xmlPullParserFactory.setNamespaceAware(true);
        xmlPullParserFactory.setValidating(false);
 
        documentBuilderFactory = DocumentBuilderFactory.newInstance();
        // XMPP requires namespace awareness 
        documentBuilderFactory.setNamespaceAware(true);
        // slightly normalize 
        documentBuilderFactory.setCoalescing(true);
        documentBuilderFactory.setIgnoringComments(true);
        documentBuilderFactory.setIgnoringElementContentWhitespace(false);
        // No includes / outbound references 
        documentBuilderFactory.setExpandEntityReferences(false);
        documentBuilderFactory.setValidating(false);
    } 
 
    /** 
     * Read a stanza from a xml stream. This does not include the connection 
     * related stanza settings like the via tag. 
     * @param xmlPullParser The XML PullParser of the current stream. 
     * @return The read stanza. 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getClass, newDocumentBuilder
	public Document loadDocument(InputSource inputSource, EntityResolver entityResolver,
			ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception {
 
		DocumentBuilderFactory factory = createDocumentBuilderFactory(validationMode, namespaceAware);
		if (logger.isDebugEnabled()) {
			logger.debug("Using JAXP provider [" + factory.getClass().getName() + "]");
		} 
		DocumentBuilder builder = createDocumentBuilder(factory, entityResolver, errorHandler);
		return builder.parse(inputSource);
	} 
 
	/** 
	 * Create the {@link DocumentBuilderFactory} instance. 
	 * @param validationMode the type of validation: {@link XmlValidationModeDetector#VALIDATION_DTD DTD} 
	 * or {@link XmlValidationModeDetector#VALIDATION_XSD XSD}) 
	 * @param namespaceAware whether the returned factory is to provide support for XML namespaces 
	 * @return the JAXP DocumentBuilderFactory 
	 * @throws ParserConfigurationException if we failed to build a proper DocumentBuilderFactory 
	 */ 
	protected DocumentBuilderFactory createDocumentBuilderFactory(int validationMode, boolean namespaceAware)

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: newDocumentBuilder, setNamespaceAware
This code example shows how to use the following methods: setAttribute, setNamespaceAware, setValidating
 
   static { 
 
      documentBuilderFactory = DocumentBuilderFactory.newInstance();
 
      documentBuilderFactory.setAttribute(
               "http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); 
      documentBuilderFactory.setAttribute(
               "http://apache.org/xml/features/nonvalidating/load-external-dtd", false); 
 
      documentBuilderFactory.setNamespaceAware(false);
      documentBuilderFactory.setValidating(false);
 
   } 
 
   /** 
    * Creates a new DocumentBuilder which does not validate document an is not aware of XML 
    * namespaces. 
    *  
    * @return The created DocumentBuilder 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: newDocumentBuilder, setNamespaceAware, setValidating
            if ( dbf == null ) {
                dbf = DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware( true );
                dbf.setValidating( false );
            } 
            db = dbf.newDocumentBuilder();
 
            DOMImplementation dim = db.getDOMImplementation();
            d = dim.createDocument("http://java.sun.com/jaxp/xpath",
                "dummyroot", null); 
            return d;
        } catch ( Exception e ) {
            e.printStackTrace();
        } 
        return null; 
    } 
 
 
 
 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: setIgnoringComments, setIgnoringElementContentWhitespace, setNamespaceAware
This code example shows how to use the following methods: newDocumentBuilder, setNamespaceAware, setValidating
    protected static DocumentBuilderFactory dbf;
    protected static DocumentBuilder db;
 
    static { 
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(false);
        dbf.setNamespaceAware(true);
 
        try { 
            db = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            SoapUI.logError(e);
        } 
    } 
 
    protected static Document getWssDocument(SubmitContext context) throws SAXException, IOException {
        String request = (String) context.getProperty(BaseHttpRequestTransport.REQUEST_CONTENT);
        Document doc = (Document) context.getProperty(WSS_DOC);
 
        // this should be solved with pooling for performance-reasons.. 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: newDocumentBuilder, setNamespaceAware, setValidating
 
    public static void main(String[] args) throws Exception {
 
        Init.init(); 
        dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        validate("signature-enveloping-hmac-sha1-trunclen-0-attack.xml", false); 
        validate("signature-enveloping-hmac-sha1-trunclen-8-attack.xml", false); 
        // this one should pass 
        validate("signature-enveloping-hmac-sha1.xml", true); 
        generate_hmac_sha1_40(); 
 
        if (atLeastOneFailed) {
            throw new Exception
                ("At least one signature did not validate as expected"); 
        } 
    } 
 
    private static void validate(String data, boolean pass) throws Exception {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: isNamespaceAware, newDocumentBuilder, setNamespaceAware
 
    /** 
     * javax.xml.parsers.DocumentBuilderFactory#setNamespaceAware(boolean). 
     */ 
    public void test_setNamespaceAwareZ() { 
        dbf.setNamespaceAware(true);
        assertTrue(dbf.isNamespaceAware());
 
        try { 
            DocumentBuilder parser = dbf.newDocumentBuilder();
 
            Document document = parser.parse(getClass().getResourceAsStream(
                    "/recipt.xml")); 
 
            assertNotNull(document);
 
        } catch (IOException e) {
            fail("Unexpected IOException " + e.getMessage());
        } catch (ParserConfigurationException e) {
            fail("Unexpected ParserConfigurationException " + e.getMessage());

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: newDocumentBuilder
	 * @throws ParserConfigurationException if thrown by JAXP methods 
	 */ 
	protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
			throws ParserConfigurationException {
 
		return factory.newDocumentBuilder();
	} 
 
	/** 
	 * Create an {@code XMLReader} that this marshaller will when passed an empty {@code SAXSource}. 
	 * @return the XMLReader 
	 * @throws SAXException if thrown by JAXP methods 
	 */ 
	protected XMLReader createXmlReader() throws SAXException {
		XMLReader xmlReader = XMLReaderFactory.createXMLReader();
		xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
		if (!isProcessExternalEntities()) {
			xmlReader.setEntityResolver(NO_OP_ENTITY_RESOLVER);
		} 
		return xmlReader;
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 DocumentBuilderFactory Questions & Answers:

Other Java 8 DocumentBuilderFactory Examples

1:			Document doc = null;
2:			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
3:			try {
4:

Read More

63:			Document doc = null;
64:			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
65:			try {
66:	
67:				DocumentBuilder db = dbf.newDocumentBuilder();

Read More

63:			Document doc = null;
64:			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
65:			try {
66:	
67:				DocumentBuilder db = dbf.newDocumentBuilder();

Read More

See Code Examples for Java 8 DocumentBuilderFactory Methods: