Java XML DocumentBuilder Create newDocumentBuilder(boolean ignoreWhitespace, boolean ignoreComment)

Here you can find the source of newDocumentBuilder(boolean ignoreWhitespace, boolean ignoreComment)

Description

new Document Builder

License

Open Source License

Declaration

public static DocumentBuilder newDocumentBuilder(boolean ignoreWhitespace, boolean ignoreComment) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class Main {

    public static DocumentBuilder newDocumentBuilder(boolean ignoreWhitespace, boolean ignoreComment) {
        try {// w w  w. j a  v a  2  s .  c om
            DocumentBuilderFactory dbf = createDefaultDocumentBuilderFactory();
            dbf.setIgnoringElementContentWhitespace(ignoreWhitespace);
            dbf.setIgnoringComments(ignoreComment);
            return dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            //not occur
            e.printStackTrace();
            throw new IllegalStateException(e);
        }
    }

    public static final DocumentBuilderFactory createDefaultDocumentBuilderFactory() {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setCoalescing(true);
        dbf.setExpandEntityReferences(true);
        dbf.setIgnoringComments(true);
        dbf.setIgnoringElementContentWhitespace(true);
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
        dbf.setXIncludeAware(true);
        return dbf;
    }
}

Related

  1. newDocumentBuilder()
  2. newDocumentBuilder()
  3. newDocumentBuilder()
  4. newDocumentBuilder()
  5. newDocumentBuilder(Boolean disallowDoctypeDecl)
  6. newDocumentBuilder(boolean nsAware, boolean validating)
  7. newDocumentBuilder(Schema schema, boolean isNamespaceAware, boolean isXIncludeAware)
  8. newDocumentBuilderFactory()
  9. newDocumentBuilderFactory()