StAX: Get EntityReferences in XML file

The content in a tag does not get returned complete. The return text only has the part before entity reference.

Opening repository resource always open the default text editor and doesn&apos;t
	honor any mapping between resource types and editors.

In the XML snippet above, it contains a ['] inside. The event.asCharacters().getData() does not return all text, but only the part before ['].

if (event.asStartElement().getName().getLocalPart().equals("thetext")) {
	event = eventReader.nextEvent();
					System.out.println("thetext: " + event.asCharacters().getData());

The problem is fixed by set one of input factory's properties.

inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);

This requires the parser to replace internal entity references with their replacement text and report them as characters.


Category >> StAX  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";
  • Arun Selvan

    Thanks for the code.. Its very helpful………..

  • SJ

    What a lifesaver! Thanks You!