I have downloaded the binary release of Xerces 1.0.1 for Java and tried to
use its DOM parser to parse a xml file (with a dtd file for validation)
using the following code:

try {
  DOMParser parser = new DOMParser();
  parser.setFeature("http://xml.org/sax/features/validation",true);
  parser.parse(uri);
  doc = parser.getDocument();
}
catch(Exception e)
{
 ...
}

The problem is although there's an element ("Abbreviation" - see below xml
and dtd) in the xml file which is not defined in the dtd file, I haven't got
any exception. However when I use Microsoft XML Notepad I got an error
message about the undefined element.

The XML file is:

<?xml version="1.0"?>
<!DOCTYPE mystore SYSTEM "mystore.dtd">

<mystore>
<items>
  <book Name="xml spec" Code="9001">
   <Abbreviation>xml</Abbreviation>
   <Author>xml.org</Author>
  </book>
..
</items>
</mystore>

The dtd is defined as follows:

<!ELEMENT mystore items>
<!ELEMENT items (book)*>
<!ELEMENT book (Abbr?,Author*)>
<!ATTLIST book Name CDATA #REQUIRED Code CDATA #REQUIRED>
<!ELEMENT Abbr (#PCDATA)>
<!ELEMENT Author (#PCDATA)>

Is it a bug or am I missing something in the code? I'm using
JDK1.2.2/Windows NT4 + SP5/Xerces1.0.1 for Java.

Li


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

Reply via email to