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]