Validating an XML document?

From: Remco Rijnders (remco_at_webconquest.com)
Date: 07/31/04


Date: Sat, 31 Jul 2004 16:58:31 +0200


Hi all,

Setting my first small steps in the world that is Java, I'm working on a
program that can be configured using a configuration file. Since this is
2004 and I don't want to be left out on all the hype, I thought it would
be nice if the configuration file would be in XML format.

I took a first shot at creating a test format for the configuration file
and parsed the file using the methods available to me after importing:

import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXParseException;

So far so good. Missing a proper closing tag in the config file results in
an exception being thrown, so I feel quite confident now that the
configuration file is a valid XML document. However, I can't tell if this
XML document is a valid configuration file for my program. I've now
included a reference to a .dtd file in the configuration file. I know the
dtd is being read, because it did give me errors like:

Line 1: No content model may contain ")".

However, once I fixed that, no errors occurred anymore while the XML
document was clearly invalid still.

The .dtd consists of the following two lines:

<!ELEMENT ircd_configuration (network,server)>
<!ELEMENT network (bla)>

I'd expect a complaint about server and bla being mentioned but not
defined. Also, if I'd misspell ircd_configuration as ircdconfiguration or
anything else, no error is thrown.

How can I make sure the configuration file validates according to the DTD?

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Relevant Pages