This Example shows you how to prevent expansion of entity references while parsing an XML file in a DOM document. JAXP (JavaAPI for XML Processing) is an interface which provides parsing of xml documents. Here the Document BuilderFactory is used to create new DOM parsers.There are some of the methods used in code given below for Preventing Expansion of Entity References:-
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance():- This method Creates a DocumentBuilder Factory .DocumentBuilder Factory is a Class that enables application to obtain parser for building DOM trees from XML Document
DocumentBuilder builder = Factory.newDocumentBuilder():-This method creates a DocumentBuilder object with the help of a DocumentBuilderFactory
File file = new File("Document4.xml"):-Creates a new File.
builderFactory.setExpandEntityReferences(false):-This method specifies that the parser produced by this code will expand entity reference nodes
TransformerFactory factory = TransformerFactory.newInstance():-TransformerFactory is a class that is used to create Transformer objects. A TransformerFactory instance can be used to create Transformer and Templates objects.
transformer.transform(source, result):-This function organize data according to a style sheet as we are retrieving it from the File.
XML code for the program generated is:-
<?xml version="1.0" encoding="UTF-8"?>
|
PreventingExpansionofEntityReferences.java
/*
|
Output of the program:-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
Recommend the tutorial |
Ask Questions? Discuss: Preventing Expansion of Entity References View All Comments
Post your Comment