[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" ?>

        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"


Sample tag library template. 
Contains one sample tag with an attribute and a variable. 
A sample tag. 



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();
      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 " +
        List attributesList = tag.getChildren("attribute");
        System.out.println(" (it has " + attributes.size() + "
    } catch (JDOMException ex) {

The expected output should be:

This TLD has 1 tags:
        sample for A sample tag. (it has 0 attributes)

Instead I get:
This TLD has 0 tags:

I switched the builder to be of type DOMBuilder and it works as

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+) >
	  xmlns CDATA #FIXED

removing the
   xmlns CDATA #FIXED

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 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. 

More information about the jdom-interest mailing list