Example usage for javax.xml.parsers DocumentBuilder isNamespaceAware

List of usage examples for javax.xml.parsers DocumentBuilder isNamespaceAware

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder isNamespaceAware.

Prototype


public abstract boolean isNamespaceAware();

Source Link

Document

Indicates whether or not this parser is configured to understand namespaces.

Usage

From source file:Main.java

/**
 * @param string Creates a {@link Document} from a string.
 * @return A {@link Document} representation of the string.
 * @throws ParserConfigurationException if a DocumentBuilder cannot be
 * created which satisfies the configuration requested
 * @throws SAXException if any parse errors occur
 * @throws IOException if any IO errors occur.
 *
 *//*w w w.  j  ava2  s  .co  m*/
public static Document stringToXml(String string)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(string));
    if (builder.isNamespaceAware()) {
        System.out.println("#######################3Is aware");
    } else {
        System.out.println("#######################Not aware");
    }
    return builder.parse(is);
}

From source file:cz.muni.fi.mir.mathmlunificator.utils.DOMBuilderTest.java

@Test
public void testGetDocumentBuilder() throws ParserConfigurationException {
    DocumentBuilder docBuilder = DOMBuilder.getDocumentBuilder();
    assertNotNull(docBuilder);//from w  ww .j a  v a 2 s.  c om
    assertTrue(docBuilder.isNamespaceAware());
}