[jdom-interest] XML DTD validation using JDOM
niranjan kumar maturi
niranjanmaturi at rediffmail.com
Wed Sep 4 23:36:53 PDT 2002
Hi,
I am trying to validate a XML file with a DTD file using JDOM.
When I write a DTD file and its corresponding XML file, they are
being validated as expected.
But for our homepage, we are using a pretty big standard DTD
file:
http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd
When i try to validate using this DTD file, i am getting errors
not with the XML file but with the DTD file like:
Error on line 31 of document
http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd: Next
character must be ">" terminating <!ENTITY...> declaration
"%HTML.Version".
Is it that dtd has versions, and the parsers i am using support an
older version??? I am also using the latest SAX 2.0.1 parser. So i
dont understand what the problem is???
The source code:
package samples;
import java.io.*;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
public class SAXBuilderDemoTest {
public static void main(String[] args)
{
if ((args.length < 1) || (args.length > 3))
{
System.out.println(
"Usage: java samples.SAXBuilderTest " +
"[XML document filename] ([expandEntities] [SAX Driver
Class])");
return;
}
boolean expandEntities = true;
// Load filename and SAX driver class
String filename = args[0];
String saxDriverClass = null;
if (args.length > 1) {
if (args[1].equalsIgnoreCase("false")) {
expandEntities = false;
}
if (args.length > 2) {
saxDriverClass = args[2];
}
}
// Create an instance of the tester and test
try {
SAXBuilder builder = null;
if (saxDriverClass == null) {
builder = new SAXBuilder(true);
} else {
builder = new SAXBuilder(saxDriverClass, true);
}
builder.setExpandEntities(expandEntities);
Document doc = builder.build(filename);
XMLOutputter outputter = new XMLOutputter();
outputter.output(doc, System.out);
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Thanks
Niranjan Maturi
More information about the jdom-interest
mailing list