SAXParserFactory getFeature() Method



Description

The Javax.xml.parsers.SAXParserFactory.getFeature(String name) method returns the particular property requested for in the underlying implementation of org.xml.sax.XMLReader.

Declaration

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

public abstract boolean getFeature(String name)

Parameters

name − The name of the property to be retrieved.

Return Value

This method does not return a value.

Exception

  • ParserConfigurationException − if a parser cannot be created which satisfies the requested configuration.

  • SAXNotRecognizedException − When the underlying XMLReader does not recognize the property name.

  • SAXNotSupportedException − When the underlying XMLReader recognizes the property name but doesn't support the property.

Example

The following example shows the usage of Javax.xml.parsers.SAXParserFactory.getFeature() method.

package com.tutorialspoint;

import javax.xml.parsers.SAXParserFactory;

public class SAXParserFactoryDemo {

   public static void main(String[] args) {

      // create a new SAXParserFactory
      SAXParserFactory factory = SAXParserFactory.newInstance();

      try {
         // get the feature status
         boolean status =
            factory.getFeature("http://xml.org/sax/features/namespaces");

         // print the status
         System.out.println("" + status);

         // set the feature of namespaces
         factory.setFeature("http://xml.org/sax/features/namespaces", true);

         // get the feature status
         status =
            factory.getFeature("http://xml.org/sax/features/namespaces");

         // print the status
         System.out.println("" + status);

      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

If we compile the code and execute it, this will produce the following result −

false
true
javax_xml_parsers_saxparserfactory.htm
Advertisements