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
>
>

Reply via email to