I want to parse xml files that have elements like these:
<element>&</element>
<element>&</element>
But SAX Parser is giving me the following exception during parsing:
org.xml.sax.SAXParseException: The reference to entity "amp" must end with the ';' delimiter.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
is there any known workaround for this?
The java code that throws the exception is this:
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
I’m unable to reproduce this with the XML you’ve shown (before your edit). Short but complete program:
With a file of:
… it runs with no error.
When the file is just:
… it shows the same exception you reported.
My conclusion is that it’s correct, and your file is broken. Look for every occurrence of
&in the file, and find where it’s missing a semi-colon.