Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating XML from an InputStream opposed to a File

Status
Not open for further replies.

link102

Programmer
Jan 4, 2005
7
US
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
 
Did you ever figure this out. I'm having the same problem.
My application works great when I use a file, but when I try to parse an InputStream, it does not work.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top