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

private static DocumentBuilderFactory getDocumentBuilderFactory(boolean isNamespaceAware) {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(isNamespaceAware);
    return dbf;//from ww w. ja v a2s  .co  m
}

From source file:Main.java

private static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
    // SAXParsers are not concurrency compatible, so always return a new instance to prevent thread issues 
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    return dbf.newDocumentBuilder();
}

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 getDocFromBuffer(byte[] buf) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);

    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(buf));

    return doc;//from www  . j a v a 2  s . c o  m
}

From source file:Main.java

public static Document createNewDocument() throws ParserConfigurationException {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(false);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    return builder.newDocument();
}

From source file:Main.java

public static DOMSource fileToDomSrc(String path) throws Exception {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder builder = dbFactory.newDocumentBuilder();
    Document document = builder.parse("file:///music/order/soap.xml");
    DOMSource domSource = new DOMSource(document);
    return domSource;
}

From source file:Main.java

public static DocumentBuilder getDOMBuilder() throws ParserConfigurationException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);/* ww w  .j a  va2s.c  o m*/
    DocumentBuilder builder = dbf.newDocumentBuilder();
    return builder;
}

From source file:Main.java

/**
 * Creates a new and empty XML document//  www .  j  av a  2s.com
 * @return New XML document
 * @throws ParserConfigurationException
 */
public static Document createNewDocument() throws ParserConfigurationException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    DocumentBuilder builder = dbf.newDocumentBuilder();
    return builder.newDocument();
}

From source file:Main.java

public static Document file2Document(File file) throws Exception {
    if (file == null || !file.exists()) {
        throw new IllegalArgumentException("File must exist![" + file == null ? "NULL"
                : ("Could not be found: " + file.getAbsolutePath()) + "]");
    }/*  w w  w .  j  a va 2  s.  c o m*/
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    return dbFactory.newDocumentBuilder().parse(new FileInputStream(file));
}

From source file:Main.java

/**
 * Cria um documento XML vazio//from  w w  w . j  a  v  a2s  . c o m
 * @return Document -> novo documento XML 
 * @throws Exception
 */
public static Document criarDocumentoXMl() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db;
    db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    return doc;
}