SAXParserFactory setValidating() Method



Description

The Javax.xml.parsers.SAXParserFactory.setValidating(boolean validating) method specifies that the parser produced by this code will validate documents as they are parsed. By default the value of this is set to false.

Declaration

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

public void setValidating(boolean validating)

Parameters

validating − true if the parser produced by this code will validate documents as they are parsed; false otherwise.

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of Javax.xml.parsers.SAXParserFactory.setValidating() 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 {

         // check if our factory parsers are validating
         System.out.println("" + factory.isValidating());

         // change this setting
         factory.setValidating(true);

         // check if our factory parsers are validating
         System.out.println("" + factory.isValidating());

      } 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