Example usage for javax.xml.parsers DocumentBuilderFactory setNamespaceAware

List of usage examples for javax.xml.parsers DocumentBuilderFactory setNamespaceAware

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilderFactory setNamespaceAware.

Prototype


public void setNamespaceAware(boolean awareness) 

Source Link

Document

Specifies that the parser produced by this code will provide support for XML namespaces.

Usage

From source file:Main.java

public static Document fromXML(String xml) throws ParserConfigurationException, IOException, SAXException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setIgnoringElementContentWhitespace(true);
    DocumentBuilder builder = factory.newDocumentBuilder();

    return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
}

From source file:Main.java

public static Document getDocument(String xml) throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
}

From source file:Main.java

/**
 * Creates and configures a DocumentBuilderFactory for use with DOM. The
 * returned DocumentBuilderFactory is namespace aware and the parsers
 * constructed with it will not eliminate whitespace in elements.
 * //from  ww w.  j a va 2 s  .  c om
 * @return Properly configured DocumentBuilderFactory
 */
static DocumentBuilderFactory createDOMFactory() {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);
    domFactory.setIgnoringElementContentWhitespace(false);
    return domFactory;
}

From source file:Main.java

/**
 * Factory method to create a new XML document object.
 * @return//from  ww w.  ja  v  a 2 s .  c  o m
 */
public static final Document newXmlDocument() throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder builder = dbf.newDocumentBuilder();
    Document xmlDocument = builder.newDocument();

    return xmlDocument;
}

From source file:Main.java

public static synchronized DocumentBuilderFactory getDOMFactory() {
    if (DOM_FACTORY == null) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setExpandEntityReferences(false);
        DOM_FACTORY = factory;//from   ww  w.  j  a  v  a  2  s .  c  om
    }
    return DOM_FACTORY;
}

From source file:Main.java

public static Document novoDocument() {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder builder = null;
    try {/* w  w  w . java2  s.  co  m*/
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }

    return builder.newDocument();
}

From source file:Main.java

public static Document getDocumentFromStream(InputStream is, boolean namespaceAware) {
    try {/*www. j  a va  2 s  .c  o  m*/
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(namespaceAware);
        DocumentBuilder builder = dbf.newDocumentBuilder();
        Document ret = builder.parse(is);
        return ret;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    setUpSecurity(dbFactory);/*  w  ww . j av a  2 s.  c  om*/
    return dbFactory.newDocumentBuilder();
}

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 Document newDocument() throws ParserConfigurationException {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true); // never forget this!

    Document doc = domFactory.newDocumentBuilder().newDocument();
    return doc;//from   w  w  w.j av  a 2s  .c  o  m
}