[jdom-interest] Problem with DOCTYPE and SAXBuilder
Ewan Harrow
eharrow at yahoo.com
Wed Jan 17 02:46:01 PST 2001
Thanks for that it indeed does now work with SAXBuilder... but not with
DOMBuilder now - I assume because it is broken with beta 5. I'll try
with the latest build.
--- Jason Hunter <jhunter at collab.net> wrote: > Here's what's going on.
The following in the DTD...
>
> <!ATTLIST taglib id ID #IMPLIED
> xmlns CDATA #FIXED
>
> "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"
> >
>
> sets the default namespace to http://java.sun.com/..... This
> requires
> that when you access an element by name in JDOM you pass in the
> proper
> Namespace for the element like this:
>
> Namespace ns = Namespace.getNamespace("", "http://.....");
> List tags = taglib.getChildren("tag", ns);
>
> You were asking for children outside a namespace, of which there were
> none. When you removed the xmlns in the DTD, then things worked as
> expected. The reason DOMBuilder "worked" for you without you needing
> to
> pass in a namespace is because DOMBuilder namespaces in beta5 were
> broken and those elements weren't being put in the proper namespace.
> DOMBuilder is fixed in the latest snapshot, so you'll need to do the
> right thing now always, as shown above.
>
> -jh-
>
> Ewan Harrow wrote:
> >
> > 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/
> > _______________________________________________
> > To control your jdom-interest membership:
> >
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
=====
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