function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Handling ENTITY_REFERENCE when parsing XML

I'm using the XmlStreamReader class to parse through an XML response from a REST service. One of the elements is a string and can contain entity references -- like "&". So, if the element value is "this & that", a reader.getText() will only return "this " because the entity reference constitutes a different event.


I can do a and check to see if the event is an XmlTag.ENTITY_REFERENCE, but then how do I get at what the actual entity reference is and then translate that back to the real character?



Best Answer chosen by Admin (Salesforce Developers) 

I realized that by setting the reader.setCoalescing(true) will resolve the issue so I don't need to worry about the character entities either way.


So in the example below, after setCoalescing is set to true, doing a getText will return "this & that".