[jdom-interest] From JSR-102 comments

Bart Read bart at wdi.co.uk
Wed Jun 13 02:46:44 PDT 2001


Gentlemen,


Thanks for your swift responses, and let me first apologise for my lack of
clarity.  I also apologise for sending my first e-mail to the wrong place --
the "Contact" link I found on one of the pages at jdom.org had been
disabled.

I used the following code to read in and parse the XML document in question
using the Apache Xerces SAX parser v1.3.1:

    public void build(File spec, OutputStream out)
    {
        ...
        ...
            SAXBuilder builder = new SAXBuilder(true);
            Document doc = builder.build(spec);
        ...
        ...
    }

Under these circumstances, and using the attached DTD and XML document the
resultant Document object does not contain any elements with attributes
whose default values (if any) have been set -- I'm thinking specifically of
the 'container' attribute belonging to the 'boxlayout' element.  Note that
validation is switched on, and that if there is any other validation error
whilst parsing the document then an exception is thrown, as expected.  Also,
this is one of those rare things -- an application that will always be using
validation.

However, if I run the SAXParserDemo (also attached) from Brett McLaughlin's
book with validation switched on and all other settings the same (document,
DTD, parser) then the default values ARE returned as part of the output from
the parser.  This is what I would expect from a validating parser, although
obviously it would be completely unreasonable to expect it with validation
turned off.

I apologise for harping on about this but I really think that under
validating conditions JDOM should return all attribute values, including
default values, because at the end of the day what a default value says is,
"this attribute is required and if there is no other value specified then it
must be assigned this default value".  In other words, the document isn't
valid without it.

Evidently this isn't the end of the world, because for the moment I can just
specify a value for the attribute(s) in question within the XML or assume
the presence of the default value in my code (yuk!).


Kind regards,


=================================
Bart Read
Senior Developer
Abbotsbury Software Ltd
Abbotsbury, DORSET DT3 4JT
Tel: +44 (0) 1305 871644
E-mail: bart at wdi.co.uk
=================================
----- Original Message -----
From: <philip.nelson at omniresources.com>
To: <jhunter at collab.net>; <jdom-interest at jdom.org>; <bart at wdi.co.uk>
Sent: Tuesday, June 12, 2001 10:41 PM
Subject: RE: [jdom-interest] From JSR-102 comments


>
> > > I just started using JDOM beta 6 a couple of weeks ago and have been
> > > very impressed by it's performance and ease of use.
> > However, I believe
> > > I may have found a small bug involving attribute default
> > values.  If I
> > > specify an attribute with a default value in the DTD, and use the
> > > corresponding element in a document but without specifying
> > a value for
> > > the attribute, then the attribute does not appear in the
> > element's list
> > > of attributes.
> >
> > The default attributes are added by the parser, and they will
> > appear if
> > you build the document using a parser.  You probably built
> > the document
> > using constructors, and in that case you got exactly the
> > elements/attributes you created.  JDOM doesn't look to the
> > DTD; it does
> > exactly what you dictate.  Considering that when elements are created
> > they exist outside a document, and can later move between
> > documents, it
> > doesn't make much sense to try to be fancy about default
> > attribs.  It's
> > the same with DOM as I understand it.
>
> I am not sure what parser this person used or what the dtd actually looked
> like, but this was exactly the problem some of the xerces parsers seemed
to
> have with the svg dtd which included default values in parameter entities.
>
> ---------- Automatically inserted by mailhost.wdi.co.uk ------------
> This message has been scanned for virus, trojans, illegal relays and
> spam. If you have any comments, problems or questions please do not
> hesitate to contact:
> Abbotsbury Software Ltd
> Tel: +44 1305 871543 Fax: +44 1305 871688
> Email: postmaster at wdi.co.uk
> Web: http://www.wdi.co.uk/virus.phtml
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: formset.dtd
Type: application/octet-stream
Size: 10252 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010613/c6d986d8/formset.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NT_SubscriberDetailsJPanel.xml
Type: text/xml
Size: 5262 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010613/c6d986d8/NT_SubscriberDetailsJPanel.xml
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SAXParserDemo.java
Type: application/x-javascript
Size: 4685 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20010613/c6d986d8/SAXParserDemo.js


More information about the jdom-interest mailing list