DocumentBuilderFactory setExpandEntityReferences() Method



Description

The Javax.xml.parsers.DocumentBuilderFactory.setExpandEntityReferences(boolean expandEntityRef) method specifies that the parser produced by this code will expand entity reference nodes. By default the value of this is set to true

Declaration

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

public void setExpandEntityReferences(boolean expandEntityRef)

Parameters

expandEntityRef − true if the parser produced will expand entity reference nodes; false otherwise.

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of Javax.xml.parsers.DocumentBuilderFactory.setExpandEntityReferences() method.

package com.tutorialspoint;

import javax.xml.parsers.DocumentBuilderFactory;

public class DocumentBuilderFactoryDemo {

   public static void main(String[] args) {

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

      // change this configuration
      factory.setExpandEntityReferences(false);

      // check if factory is configured to produce parsers
      System.out.println("" + factory.isExpandEntityReferences());


   }
}

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

false
javax_xml_parsers_documentbuilderfactory.htm
Advertisements