[jdom-interest] Problem with DOCTYPE and SAXBuilder
Ewan Harrow
eharrow at yahoo.com
Tue Jan 16 03:43:32 PST 2001
I am new to JDOM but I am having a spot of difficulty getting any
children of the root element using a document created with SAXBuilder
and a particular DTD. The xml below is from a JSP Taglib TLD.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE JSPTAGLIB.1_1
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>sample</shortname>
<info>
Sample tag library template.
Contains one sample tag with an attribute and a variable.
</info>
<tag>
<name>sample</name>
<tagclass>pkg.SampleTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>
A sample tag.
</info>
<attribute>
<name>sampleAttribute</name>
<type>String</type>
<rtexprvalue>true</rtexprvalue>
<required>false</required>
</attribute>
</tag>
</taglib>
My code is as follows:
...
SAXBuilder builder = new SAXBuilder();
//DOMBuilder builder = new DOMBuilder();
try {
// Build the JDOM Document
Document doc = builder.build(new File("taglib.tld"));
//Document doc = builder.build(file);
Element taglib = doc.getRootElement();
System.out.println(taglib.getName());
List tags = taglib.getChildren("tag");
System.out.println("This TLD has "+ tags.size() +" tags:");
Iterator i = tags.iterator();
while (i.hasNext()) {
Element tag = (Element) i.next();
System.out.print("\t" + tag.getChild("name").getTextTrim() +
" for " +
tag.getChild("info").getTextTrim());
List attributesList = tag.getChildren("attribute");
System.out.println(" (it has " + attributes.size() + "
attributes)");
}
} catch (JDOMException ex) {
System.out.println(ex);
}
The expected output should be:
taglib
This TLD has 1 tags:
sample for A sample tag. (it has 0 attributes)
Instead I get:
taglib
This TLD has 0 tags:
I switched the builder to be of type DOMBuilder and it works as
expected.
Is this a bug or expected behaviour? I am using JDOM-B5, jdk1.3,
win2000. If it helps I had the same problem using Xalan XPath support
- and narrowed the problem down to the DTD and a namespace issue. The
DTD for tld files has a taglib element defined as
<!ELEMENT taglib (tlibversion, jspversion?, shortname, uri?, info?,
tag+) >
<!ATTLIST taglib id ID #IMPLIED
xmlns CDATA #FIXED
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"
>
removing the
xmlns CDATA #FIXED
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"
and running again with XPath/Xalan and SAXBuilder did the trick.
While I am at it when setting the DOCTYPE to SYSTEM the URI of the DTD
(same directory as tld) needed a path from the working directory with
DOMBuilder but not SAXBuilder - got a JDOMException file not found.
Ewan
=====
Ewan Harrow ewan at harrow.org
mb: 07092 108950 http://www.harrow.org
http://www.ewanharrow.com http://travel.ewanharrow.com
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
More information about the jdom-interest
mailing list