What you said are exactly right. I need to set an error handler for
xerces-J's API call. After setting it, the program works fine with good xsd
and produced errors as expected with some bad xsd files with Xerces-J
version 1.4.2.

But for JAXP1.1 when I dbf.setValidating(true) to turn validation on, it
still complains about Elements must be declared even though the same XML/XSD
files used in the above testcase was used. It seems to me that the
DocumentBuilder object obtained from JAXP1.1 failed to recognize the schema
file, but it works fine with XML file with dtd as schema. It has the same
behavior in both Xerces 1.3.1 and 1.4.2.

--Bin

-----Original Message-----
From: Edwin Goei [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 27, 2001 10:30 AM
To: [EMAIL PROTECTED]
Subject: Re: Using JAXP with Xerces-J Question


Bin Xu wrote:
> 
> But when I try to use JAXP1.1 (It is suggested that better to use it for
> better interoperation with different parsers), it is not working:
>       DocumentBuilderFactory dbf =
>             DocumentBuilderFactoryImpl.newInstance();
> 
>         dbf.setValidating(true);
>         DocumentBuilder db = dbf.newDocumentBuilder();
> 
>         ==>It did not work, the complaints are:
> F:\>java TestXerces personal-schema.xml
> Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
> set, which is probably not what is desired.  Parser will use a default
> ErrorHandler to print the first 10 errors.  Please call
> the 'setErrorHandler' method to fix this.
> Error: URI=null Line=3: Element type "personnel" must be declared.
> Error: URI=null Line=5: Element type "person" must be declared.
> Error: URI=null Line=6: Element type "name" must be declared.
> Error: URI=null Line=6: Element type "family" must be declared.
> Error: URI=null Line=6: Element type "given" must be declared.
> Error: URI=null Line=7: Element type "email" must be declared.
> Error: URI=null Line=8: Element type "link" must be declared.
> Error: URI=null Line=11: Element type "person" must be declared.
> Error: URI=null Line=12: Element type "name" must be declared.
> Error: URI=null Line=12: Element type "family" must be declared.
> 
> Did I miss something here?

To validate a document, you need 3 things:
  1) a schema to validate with, e.g. a DTD reference in the input doc
  2) validation must be turned on
  3) an errorhandler must be set

It looks like you have done #1 and #2, but not #3.  The code in JAXP
sets a default errorhandler that prints the first 10 errors with a
warning telling the app to set its own.

I suspect if you do #2 using xerces specific API then #3 does not happen
so you will not get any indication of validation errors.

-Edwin

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to