I am scraping data in a XML using JAVA with DOM package. I was able to retrieve the needed information, but I'm having a problem when in the XML there are any   tags.
This is my feed.xml file:
<inventory>
<item UnitID="1234" Record="0">
<id>1234</id>
<dealerid>455</dealerid>
<stock_number>1600Xtreme</stock_number>
<details>This is some additional details   about the
product</details>
<make>Nvidia</make>
</item>
<item UnitID="7854" Record="1">
<id>7854</id>
<dealerid>587</dealerid>
<stock_number>12TMAX5500</stock_number>
<details>This is some additional details   about the
product</details>
<make>Realtek</make>
</item>
</inventory>
As you can see in the feed.xml, the details Tag contains a   , and whenever I run my JAVA it displays an error.
However, if I remove that line, everything works fine. Removing it is not an option, since I'm not allowed to edit the xml in real life.
This is my JAVA code:
File fXmlFile=new File("feed.xml");
DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder=dbFactory.newDocumentBuilder();
Document doc=dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList=doc.getElementsByTagName("item");
for (int temp=0; temp < nList.getLength(); temp++)
{
Node nNode=nList.item(temp);
Element eElement2 = (Element)nNode;
String search="Nvidia";
if (eElement2.getElementsByTagName("make").item(0).
getTextContent().equals(search))
{
System.out.println("The condition on the IF is True");
}
}
This is the error I get when run:
[Fatal Error] feed.xml:150:504: The entity "nbsp" was referenced, but not declared. org.xml.sax.SAXParseException; systemId: file:/C:/src/Test1/feedForTests.xml; lineNumber: 150; columnNumber: 504; The entity "nbsp" was referenced, but not declared. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:205) at Test1.ReadXMLFile2.main(ReadXMLFile2.java:58)
Just by removing the   from the details tag, the problem disapears.
I have got to this point with my code, but got stuck and cant find a solution. I appreciate your help.