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

Stephan Trebels stephan at ncube.de
Mon Jun 3 07:28:40 PDT 2002


Did you try the URI file:///c:/myfile.xml ?

On Thu, May 30, 2002 at 08:51:32PM +0200, Sergio Sierra wrote:
> 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.
> 
> 
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

-- 
           Stephan Trebels <stephan at ncube.de>, Consultant
mail: nCUBE Deutschland GmbH, Hanauer Str. 56, 80992 Munich, Germany
phone: +49 89 149893 0  cell: +49 172 8433111  fax: +49 89 149893 50 



More information about the jdom-interest mailing list