0

I am trying to parse XML response into Java object. Here is the sample xml response

Response

        <SavedSearch>
            <Id>8</Id>
            <Name>My Outstanding & Overdue mail</Name>
        <SavedSearch>

Here is my Java Pojo object where i am trying to map response

JavaResponse.java

    @XmlRootElement(name = "SavedSearch")
    public class MailSavedSearchRO {
    private String id;
    private String name;
    @XmlElement(name = "Id")
    public String getId() {
      return id;
    }

    public void setId(String id) {
      this.id = id;
    }

    @XmlElement(name = "Name")
    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }

But I am getting org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.I went through some solutions online but it was suggested that "&" should be replaced with ampersand. But the xml response is external entity and cant be modified from my end. Can anyone suggest how i can parse xml containing "&" without modifying xml response.

Sachin HR
  • 450
  • 11
  • 28
  • 2
    It seems, that XML response is not a valid XML according to the specification: https://www.w3.org/TR/xml/#syntax So it's just response, not a XML response. Some parsing advises can be found here: https://stackoverflow.com/a/44765546/2792888 – Alexandra Dudkina Dec 21 '22 at 10:06
  • 1
    I would expect the marshaler to escape that '&' to the entity `&`. How are you marshaling it? – g00se Dec 21 '22 at 12:52

0 Answers0