[jdom-interest] Validation bug reading XML from URI and not from a characterStream?

Sergio Sierra ssierra at bigfoot.com
Thu May 30 11:51:32 PDT 2002


Hi!

I have a strange behaviour with JDOM b8 when I trying to build a JDOM
tree from URI, for example ("c:\myfile.xml").

CASE A:
-------
If the same file is into a String variable (as characterStream) the
validation against the DTD is correct: if there was an error in the data
or in the DTD, the exception is thrown and i know the file is invalid o
incorrect.

CASE B:
------
However, if try to parse the same XML file with the same content and the
same DTD directly from my hard disk (URI = "c:\myfile.xml"), the
validation is not run, so the JDOM tree is built in memory and the
exception to know if the file is invalid is not thrown. So if i have a
wrong XML file, i can't know it because the JDOM tree was built in
memory like it was a valid XML file.

I have tryed to set some features, without result.

There are the code lines I use (problem persists without builder.setXXXX
lines):

------------
(...)
    String XMLfile = "<?xml version=\"1.0\"
encoding......blablabla.....";
    String XMLuri= "c:\myfile.xml";

(...)
    builder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser",true);
    builder.setExpandEntities(false);
    builder.setValidation(true);
 
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-ex
ternal-dtd", true);

============
CASE A: validation against DTD is correct if the xml is built from a
characterStream
============
    doc = builder.build(new StringReader(XMLfile));

============
CASE B: validation is off if the xml file is built from a URI, so JDOM
tree is created if the file is invalid
============
    doc = builder.build(XMLuri);                     

(...)
------------

Please, anyone have any idea of the problem?

Thanks for your help,

Sergio

P.D. I have used Xerces 1.4.4 and Xerces 2.0.1 and the problem persists.







More information about the jdom-interest mailing list