Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javax.xml.stream.XMLStreamException throws when present '&' character

793912Apr 27 2010 — edited Apr 29 2010
Hi
I am writing a code using stax parser. But recently I got an error when "&" or "&" present in the xml document.
This is the error I am getting
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[30,30]
Message: The reference to entity "name" must end with the ';' delimiter.
This is my xml
<url>  http://url?id=1&name=aaa  </url>  
This is my code
XMLInputFactory xmlInputFactory =  XMLInputFactory.newInstance();
            xmlInputFactory.setProperty(
                    XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
                    Boolean.TRUE);
            xmlInputFactory.setProperty(
                    XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
                    Boolean.FALSE);
            xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);

String xmlSource;
XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(new ByteArrayInputStream(xmlSource.getBytes("UTF-8")));

while (reader.hasNext())
{
  ....
  reader.next(); // error throws in this line
}
Can someone please help me.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2010
Added on Apr 27 2010
4 comments
1,244 views