I am trying to read an XML file with this header:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="MeasDataCollection.xsl"?>
<!DOCTYPE mdc SYSTEM "MeasDataCollection.dtd">
I create a pathName for this file in a method :
String filePathName = appProperties.getProperty("xmlFilesLocation") + "/" +
appProperties.getProperty("adaptorLA") + "/" + tempName; //tempName is the file's name, it is file.xml here
and I am trying to re-open and parse the file with such code in another method:
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = documentBuilder.parse(file);
This is where my program crashes, I get an error that the file "MeasDataCollection.dtd" does not exist. I do not excplicitly assign this file name to the path I am trying to parse, but it seems that somehow it messes with my file name.
I am struggling to understand what this "doctype ... system ..." means and how it affects my code.
All help is appreciated.
Check the answers to this question to disable DTD reading: DTD download error while parsing XHTML document in XOM
A DTD is used to define the XML structure, and can also define XML entities. If that is the case, if you don't read the DTD it is possible that the XML parsing will fail, you will have to try.