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

Alex Rosen arosen at silverstream.com
Mon Jun 3 06:56:14 PDT 2002


I think that some parsers accept "c:\myfile.xml" as a URI even though it's
not. It's better to use a real URI that starts with "file:". Use the toURL()
method on java.io.File.

Alex

> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Sergio Sierra
> Sent: Thursday, May 30, 2002 2:52 PM
> To: jdom-interest at jdom.org
> Subject: [jdom-interest] Validation bug reading XML from URI and not
> from a characterStream?
>
>
> 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/nonvalidati
> ng/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.
>
>
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com




More information about the jdom-interest mailing list