I am trying to parse the following url as a DOM Document in Java: http://www.op.org/en/rss-category-home/8.
However, when I do this, I get the following error:
13:51:38,470 ERROR ~ Error processing site Site 1
org.xml.sax.SAXParseException: The entity "acirc" was referenced, but not declared.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at logic.server.RssReader.readRss(RssReader.java:44)
at logic.server.GatherData.doJobWithResult(GatherData.java:49)
at logic.server.GatherData.doJobWithResult(GatherData.java:1)
I read somewhere that the Xerces parser in the current JRE is has a bug related to this, so downloaded Xerces2 2.11.0, but still have the same problem.
How can I get around this problem. I have no control over the RSS feed itself, but need to parse the XML to process the articles.
My code is: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document dom = builder.parse(rssUrl.openStream());
NodeList nodes = dom.getElementsByTagName("item");
etc. etc.
Any help to get around this problem is really appreciated!
EDIT: IF I would try the solution below and add the DTD, where would I do that? The current RSS element is:
<rss version="2.0" xml:base="http://www.op.org/en/rss-category-home/8" xmlns:dc="http://purl.org/dc/elements/1.1/" content="http://purl.org/rss/1.0/modules/content/" dc="http://purl.org/dc/terms/" foaf="http://xmlns.com/foaf/0.1/" og="http://ogp.me/ns#" rdfs="http://www.w3.org/2000/01/rdf-schema#" sioc="http://rdfs.org/sioc/ns#" sioct="http://rdfs.org/sioc/types#" skos="http://www.w3.org/2004/02/skos/core#" xsd="http://www.w3.org/2001/XMLSchema#">
or would I add it to every 'description' element, which containst the XHTML code, something like this? I tried this later solution, but it still gives the same error.
<description xmlns="http://www.w3.org/1999/xhtml">
If there's an error in the XML, why would you want to ignore it? XML parsers are designed to reject bad XML.
It looks like this XML includes an entity reference â
but doesn't include the DTD that defines this entity. This is one of the standard XHTML entities, so you can probably repair the XML by adding a reference to the relevant entity declaration DTD modules from XHTML.