You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by asha <le...@lecindia.com> on 1999/12/12 10:59:03 UTC

parser is not validating the xml document

I have an xml document as follows:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE catalog SYSTEM "BookDTD.dtd" >
<catalog>
    <Book>
         <Author>asha</Author>
        <Publisher>Wrox</Publisher>
        <owner>asha</owner>
   </Book>
</catalog>

And the DTD (BookDTD.dtd) is as follows :

<!ELEMENT catalog (Book)>
<!ELEMENT Book (Author,Publisher)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>

I have written a java program which will use Xerces parser to parse  the document .Program as follows :

    DOMParser parser = new DOMParser();
    parser.setFeature("http://xml.org/sax/features/validation",true);
    parser.parse("file:///i:/akl/Security.xml");

 Since document is not written as per the DTD specification. It should give me an error. But it parses the file without any error.
I have tried with Xerces2.0 version as well as Xerces1.2.3 version.
Can anybody tell me where is the problem.


Re: parser is not validating the xml document

Posted by Edwin Goei <Ed...@eng.sun.com>.
Andy Clark wrote:
> 
> asha wrote:
> >  Since document is not written as per the DTD specification. It
> > should give me an error. But it parses the file without any error.
> 
> I have solved this problem once and for all in Xerces2 by always
> calling a default error handler if the application using the
> parser has not registered an error handler. The default error
> handler just prints errors to System.err.
> 
> This is a change in behavior from previous versions of Xerces
> but I think it's for the better. The only difference is that
> if people want errors to be silently ignored, they must now
> register a no-op error handler.

This might cause lots of error messages to be written out for some
documents so a compromise would be to print a warning about setting an
error handler and then printing out only the first 10 errors.  This is
what the crimson parser does when validation is turned on.

-Edwin

Re: parser is not validating the xml document

Posted by Andy Clark <an...@apache.org>.
asha wrote:
>  Since document is not written as per the DTD specification. It 
> should give me an error. But it parses the file without any error.

I have solved this problem once and for all in Xerces2 by always
calling a default error handler if the application using the
parser has not registered an error handler. The default error
handler just prints errors to System.err.

This is a change in behavior from previous versions of Xerces
but I think it's for the better. The only difference is that
if people want errors to be silently ignored, they must now
register a no-op error handler.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org