Hello all, I have been having this problem for some time now. I can validate XML against my DTD just fine when it is a local file, however, when I try to grab it from a URI or InputStream it does not work. The same XML when parsed will throw a DOCTYPE not found error. Below is my test XML file that I am using as well as a few things I have tried. Also, the XML still builds the document when it is well formed, but it does not validate it, which must be done.
This code works:
DocumentBuilderFactory dbf = null;
DocumentBuilder db = null;
Document d = null;
dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setIgnoringComments(true);
db = dbf.newDocumentBuilder();
db.setErrorHandler(new XMLErrorHandler(new XT()));
// XT is the name of my XmlTest java file
However, when I try to parse (and most importantly) validate the XML with the following code I get errors:
// parsing from a URI
d = db.parse("
// parsing the inputstream from a URL
d = db.parse((new URL("
// converting a URL to a URI then creating a File from that and parsing it
d = db.parse(new File(new URI((new URL("
I hope I am clearly getting across what my issue is. Any help would be greatly appreciated, I have been trying to get this problem resolved for almost a month now!
Sincerely,
Jeff
This code works:
DocumentBuilderFactory dbf = null;
DocumentBuilder db = null;
Document d = null;
dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setIgnoringComments(true);
db = dbf.newDocumentBuilder();
db.setErrorHandler(new XMLErrorHandler(new XT()));
// XT is the name of my XmlTest java file
However, when I try to parse (and most importantly) validate the XML with the following code I get errors:
// parsing from a URI
d = db.parse("
// parsing the inputstream from a URL
d = db.parse((new URL("
// converting a URL to a URI then creating a File from that and parsing it
d = db.parse(new File(new URI((new URL("
I hope I am clearly getting across what my issue is. Any help would be greatly appreciated, I have been trying to get this problem resolved for almost a month now!
Sincerely,
Jeff