- Home
- Binder
- DatatypeConverter
- JAXB
- JAXBContext
- JAXBElement
- JAXBElement.GlobalScope
- JAXBIntrospector
- Marshaller.Listener
- SchemaOutputResolver
- Unmarshaller.Listener
- Javax.xml.bind.util classes
- JAXBResult
- JAXBSource
- ValidationEventCollector
- Javax.xml.parsers classes
- DocumentBuilder
- DocumentBuilderFactory
- SAXParser
- SAXParserFactory
- Javax.xml.soap classes
- AttachmentPart
- MessageFactory
- MimeHeader
- MimeHeaders
- SAAJMetaFactory
- SOAPConnection
- SOAPConnectionFactory
- SOAPFactory
- SOAPMessage
- SOAPPart
- Javax.xml.validation classes
- Schema
- SchemaFactory
- TypeInfoProvider
- Validator
- ValidatorHandler
- Javax.xml.xpath classes
- XPathConstants
- XPathFactory
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
DocumentBuilderFactory newDocumentBuilder() Method
Description
The Javax.xml.parsers.DocumentBuilderFactory.newDocumentBuilder() method creates a new instance of a DocumentBuilder using the currently configured parameters.
Declaration
Following is the declaration for Javax.xml.parsers.DocumentBuilderFactory.newDocumentBuilder() method
public abstract DocumentBuilder newDocumentBuilder()
Parameters
NA
Return Value
This method returns a new instance of a DocumentBuilder.
Exception
ParserConfigurationException − if a DocumentBuilder cannot be created which satisfies the configuration requested.
Example
The following example shows the usage of Javax.xml.parsers.DocumentBuilderFactory.newDocumentBuilder() method.
package com.tutorialspoint;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
public class DocumentBuilderFactoryDemo {
public static void main(String[] args) {
// create a new DocumentBuilderFactory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// configure the DocumentBuilder to be namespace aware
factory.setNamespaceAware(true);
try {
// create a new DocumentBuilder
DocumentBuilder builder = factory.newDocumentBuilder();
// check the configuration for namespace aware
System.out.println("" + builder.isNamespaceAware());
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
}
}
}
If we compile the code and execute it, this will produce the following result −
true
javax_xml_parsers_documentbuilderfactory.htm
Advertisements