![Javax.xml.parsers package examples](/java/xml/images/javaxml-mini-logo.jpg)
- Javax.xml.bind classes
- 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 setFeature() Method
Description
The Javax.xml.parsers.DocumentBuilderFactory.setFeature(String name, boolean value) method ets a feature for this DocumentBuilderFactory and DocumentBuilders created by this factory
Feature names are fully qualified URIs. Implementations may define their own features. A ParserConfigurationException is thrown if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support the feature. It is possible for a DocumentBuilderFactory to expose a feature value but be unable to change its state.
Declaration
Following is the declaration for Javax.xml.parsers.DocumentBuilderFactory.setFeature() method
public abstract void setFeature(String name, boolean value)
Parameters
name − Feature name.
value − Is feature state true or false
Return Value
This method does not return a value.
Exception
ParserConfigurationException − if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support this feature.
NullPointerException − If the name parameter is null.
Example
The following example shows the usage of Javax.xml.parsers.DocumentBuilderFactory.setFeature() method.
package com.tutorialspoint; 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(); try { // set the feature of namespaces factory.setFeature("http://xml.org/sax/features/namespaces", true); // get the state of the feature System.out.println("" + factory.getFeature("http://xml.org/sax/features/namespaces")); } catch (ParserConfigurationException ex) { ex.printStackTrace(); } } }
If we compile the code and execute it, this will produce the following result −
true