Try using the sample, dom.DOMCount, or dom.DOMWriter on your test case.

You will see that the test vcase is indeed invalid and the problem is that
you have not implemented an ErrorHandler, and invoked:
parser.setErrorHandler with your implementation. Simply putting
System.out.printlns
in the warning, error, and fatalError functions will show you the
validation errors.

The default of the parser is not to setErrorHandler to a specific
implementation.

We are considering setting a simple ErrorHandler that prints out the
errors as the default DOMParser implementation.

-Ralf

David Blevins wrote:

> 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>[EMAIL PROTECTED]</email>
>         </person>
>
>         <person id="two.worker">
>           <name>Joe</name>
>           <email>[EMAIL PROTECTED]</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:[EMAIL PROTECTED]
> > 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
> >
> >

--
<person name="Ralf I. Pfeiffer"
 loc="IBM JTC, Cupertino, CA"
 email1="[EMAIL PROTECTED]"
 email2="[EMAIL PROTECTED]"
/>


Reply via email to