This Example gives you the way to test EntityReferences in an XML file. JAXP (Java API for XML Processing) is an interface which provides parsing of xml documents. There are some of the methods used in code given below for Testing EntityReferences in Xml File:-
XMLInputFactory Factory = XMLInputFactory.newInstance():-By this method we create a new instance of the factory.
factory.setProperty(XMLInputFactory.IS_COALESCING, true):-This method sets the property that requires the parser to coalesce adjacent character data sections.
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true):-This method sets the parser to replace internal entity references with their replacement text.
XMLStreamReader reader = Factory.createXMLStreamReader(new FileInputStream(file)):-Creates a new StreamReader which allows forward, read-only access to XML.
Xml code for the program generated is:-
<?xml version="1.0" encoding="UTF-8"?>
|
TestingEntityReference.java
/*
|
Output of the program:-
Factory is validating: false
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Testing EntityReferences in Xml
Post your Comment