You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Jeffrey Rodriguez <je...@hotmail.com> on 2000/02/23 07:00:12 UTC

Fwd: RE: [Xerces-J] Validating a DOM doc against the DTD

David you got the parse.setFeature right. The other step needed to setup 
DOMParser to validate is to provide an errorHandler.
You need to do the following:

1) Create a class that implements  class org.xml.sax.ErrorHandler interface.
2) Register your class using using DOMParser setErrorHandler method.

For an example of this look at the the two DOM wrappers files  under 
java/samples/dom/wrappers.

Thanks,
           Jeffrey Rodriguez
           IBM Cupertino



>From: "David Blevins" <da...@visi.com>
>Reply-To: xerces-dev@xml.apache.org
>To: <xe...@xml.apache.org>
>Subject: RE: [Xerces-J] Validating a DOM doc against the DTD
>Date: Tue, 22 Feb 2000 16:35:59 -0600
>
>Here's my test case.
>
>I set the validation feature in the parser and then parse the XML document.
>
>DOMParser parser = new DOMParser();
>parser.setFeature("http://xml.org/sax/features/validation", true);
>parser.setFeature("http://apache.org/xml/features/validation/warn-on-undecla
>red-elemdef", true);
>parser.parse("personal.xml");
>
>The DTD is as such.
>
>     <?xml encoding="US-ASCII"?>
>
>     <!ELEMENT personnel (person)+>
>     <!ELEMENT person (name,email*)>
>     <!ATTLIST person id ID #REQUIRED>
>     <!ELEMENT name (#PCDATA)>
>     <!ELEMENT email (#PCDATA)>
>
>The XML is as such.
>
>     <?xml version="1.0"?>
>     <!DOCTYPE personnel SYSTEM "personal.dtd">
>
>     <personnel>
>
>       <people>
>         <person id="one.worker">
>           <name>Bob</name>
>           <email>one@foo.com</email>
>         </person>
>
>         <person id="two.worker">
>           <name>Joe</name>
>           <email>two@foo.com</email>
>         </person>
>       </people>
>
>     </personnel>
>
>The XML document is intentionally invalid.
>The parser parses out the DOM and I am able to retrieve the Document 
>object.
>No error is thrown and the DOM is incorrect.
>
>What might be the problem or am I misunderstanding something?
>
>
>
> > -----Original Message-----
> > From: David Blevins [mailto:david.blevins@visi.com]
> > Sent: Monday, February 21, 2000 5:29 PM
> > To: Xerces-Dev
> > Subject: [Xerces-J] Validating a DOM doc against the DTD
> >
> >
> > How would I go about validating a DOM against the DTD?
> >
> > I tried using org.apache.xerces.parsers.RevalidatingDOMParser and then
> > calling validate on the base element.  This returned null even
> > though there
> > were discrepancies between the Element and the DTD.
> >
> > Is there another way to go about this or am I missing something
> > basic in the
> > RevalidatingDOMParser?
> >
> > -Dave
> >
> >
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com