Javax.xml.parsers.DocumentBuilderFactory.getFeature() Method



Description

The Javax.xml.parsers.DocumentBuilderFactory.getFeature(String name) method gets the state of the named feature.

Feature names are fully qualified URIs. Implementations may define their own features. An ParserConfigurationException is thrown if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support the feature. It is possible for an DocumentBuilderFactory to expose a feature value but be unable to change its state.

Declaration

Following is the declaration for Javax.xml.parsers.DocumentBuilderFactory.getFeature() method

public abstract boolean getFeature(String name)

Parameters

name − The name of the feature.

Return Value

This method returns the state of the named feature.

Exception

ParserConfigurationException − if this DocumentBuilderFactory or the DocumentBuilders it creates cannot support this feature.

Example

The following example shows the usage of Javax.xml.parsers.DocumentBuilderFactory.getFeature() 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
javax_xml_parsers_documentbuilderfactory.htm
Advertisements