You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by David Blevins <da...@visi.com> on 2000/02/22 00:28:50 UTC

[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


Choose java/c++?Help me please.

Posted by lark hu <la...@sz.huawei.com.cn>.
I want to run 500 threads on pII500,256M,NT.
choose java or c++?
and how about the speed of each thread of java with comparision to c++.
Thanks a lot! 

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

Posted by David Blevins <da...@visi.com>.
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
>
>