Javax.xml.parsers.SAXParser.getProperty() Method



Description

The Javax.xml.parsers.SAXParser.getProperty(String name) method returns the particular property requested for in the underlying implementation of XMLReader.

Declaration

Following is the declaration for Javax.xml.parsers.SAXParser.getProperty() method

public abstract Object getProperty(String name)

Parameters

name − The name of the property to be retrieved.

Return Value

This method returns the value of the requested property.

Exception

  • 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.SAXParser.getProperty() method.

package com.tutorialspoint;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

public class SaxParserDemo {

   public static void main(String[] args) {

      // get a property that is commonly used
      final String property =
         "http://apache.org/xml/properties/input-buffer-size";

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

      try {
         // get a new SAXParser
         SAXParser parser = factory.newSAXParser();

         // set the property
         parser.setProperty(property, new Integer(2048));

         // get the property value
         System.out.println("" + parser.getProperty(property));

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

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

2048
javax_xml_parsers_saxparser.htm
Advertisements