You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by William Lee <wl...@sendmail.com> on 2001/03/09 23:00:35 UTC

TraX not validating my document?

I seem to have a problem trying to use the DocumentBuilder to validate
my document using a DTD.  When I try the following:

DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setValidating(true);
DocumentBuilder dbuilder = dfactory.newDocumentBuilder();
Document doc = dbuilder.parse([some uri]);

However, it doesn't seem to work.  My XML file has the doctype defined:

<!DOCTYPE someroot SYSTEM "someroot.dtd">

and when I violate the someroot.dtd in the xml document, I don't really
get an error.  Why is this?

Will

Re: TraX not validating my document?

Posted by Gary L Peskin <ga...@firstech.com>.
William Lee wrote:
> 
> I seem to have a problem trying to use the DocumentBuilder to validate
> my document using a DTD.  When I try the following:
> 
> DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
> dfactory.setValidating(true);
> DocumentBuilder dbuilder = dfactory.newDocumentBuilder();
> Document doc = dbuilder.parse([some uri]);
> 
> However, it doesn't seem to work.  My XML file has the doctype defined:
> 
> <!DOCTYPE someroot SYSTEM "someroot.dtd">
> 
> and when I violate the someroot.dtd in the xml document, I don't really
> get an error.  Why is this?
> 
> Will

Will --

You're really just using Xerces here, Xalan is not involved.  So, your
question really belongs on the Xerces mailing list.  However, the
chances are the you are validating but you haven't supplied an
ErrorHandler.  In that case, all of the errors will invoke the default
ErrorHandler which probably just ignores them.  Have a look at the
org.xml.sax.ErrorHandler interface and make your own simple error
handler and the call dbuilder.setErrorHandler() with it.

Gary