[jdom-interest] Confirm my understanding about dtds/schema, please

Scott Ellsworth scott at alodar.com
Tue Aug 1 14:32:14 PDT 2000

Hi, all.

I have been using jdom to learn xml, along with the McLaughlin book and one 
by Benoit Marachal.  So far, it has been going well.  I have a program now 
that uses jdom (and xerxes) to write out an xml file and read it back in 
with verification.  The write seems fine, but on the read, I am getting errors.

Given my druthers, I would skip out on dtd support entirely, but schemas 
were giving me an error when I specified them as a doctype, so I decided to 
try dtds first.  I note that every example using schema also has a dtd 
referenced in the doctype, so I am now betting that this is just the way 
things are...

Here is the code that creates the xml file:
Namespace N=Namespace.getNamespace("RQbyScott", 
Element c=new Element("character", N);
c.addContent(new Element("subnode",N));
Document doc=new Document(c);
doc.setDocType(new DocType("RQbyScott:character","xmltest.dtd"));

The read is done by:

BufferedInputStream instream=null;
	SAXBuilder builder=new SAXBuilder(true);	// validate
	instream=new BufferedInputStream(new FileInputStream("out.xml"),1048576);
	Document doc=builder.build(instream);
	Element c=doc.getRootElement();
	if (it is good) System.out.println("Hunky dory");
catch(IOException e) { Debug.printWithTimeStamp("Error reading in.xml: "+e); }
catch(JDOMException e){ Debug.printWithTimeStamp("Error parsing xml: "+e); }

The dtd, xmltest.dtd is in the place I run the program from: C:\Documents 
and Settings\Scott Ellsworth\My Documents\Java\xmltest.

<!ELEMENT RQbyScott:character ( RQbyScott:subnode ) >
<!ATTLIST RQbyScott:character xmlns:RQbyScott CDATA #REQUIRED >
<!ELEMENT RQbyScott:subnode ( #PCDATA ) >

Here is the error:
2000/08/01 14:24:05 Error parsing xml: org.jdom.JDOMException: File 
"xmltest.dtd" not found.: Error on line 0: File "xmltest.dtd" not found.

So, why did this fail?

Scott Ellsworth
scott at alodar.com

More information about the jdom-interest mailing list