[jdom-interest] From JSR-102 comments

Bart Read bart at wdi.co.uk
Fri Jul 6 09:08:42 PDT 2001


Gents,


Thanks for your help and sorry not to have replied sooner -- I've been out
of the office for a couple of weeks.  I tried the same thing as you and it
seemed to work fine -- I should have read the JavaDoc about the
getAttributes() method of Element more carefully, specifically the bit about
the attributes being returned in no particular order.  I had been assuming
if validation was switched on attributes would be returned in the order
specified in the DTD.  Oops.  Schoolboy error #497 rears its ugly head
again.

Thanks again for clearing that up.


=================================
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: "Jason Hunter" <jhunter at collab.net>
To: "Bart Read" <bart at wdi.co.uk>
Cc: <philip.nelson at omniresources.com>; <jdom-interest at jdom.org>
Sent: Saturday, June 16, 2001 12:53 AM
Subject: Re: [jdom-interest] From JSR-102 comments


> Hi Bart,
>
> In testing your code I don't see the problem with Xerces 1.2 or 1.3.
> First, I confirmed boxlayout didn't have the container attribute in the
> XML.
>
> % grep boxlayout NT_SubscriberDetailsJPanel.xml
>  <boxlayout orientation="X_AXIS"/>
>  <boxlayout orientation="Y_AXIS"/>
>  <boxlayout orientation="X_AXIS"/>
>  ...
>
> Then I ran a TestOutput.java program and saw that the output had the
> container attribute added:
>
> % java TestOutput NT_SubscriberDetailsJPanel.xml | grep boxlayout
>   <boxlayout orientation="X_AXIS" container="@this" />
>   <boxlayout orientation="Y_AXIS" container="@this" />
>   <boxlayout orientation="X_AXIS" container="@this" />
>   etc
>
> So it looks OK to me.  Here's the little test program:
>
> import java.io.*;
> import java.util.*;
> import org.jdom.*;
> import org.jdom.input.*;
> import org.jdom.output.*;
>
> public class TestOutput {
>
>   public static void main(String[] args) throws Exception {
>     long before, after;
>
>     SAXBuilder b = new SAXBuilder(true);
>     Document doc = b.build(args[0]);
>
>     XMLOutputter outp = new XMLOutputter();
>     outp.output(doc, System.out);
>   }
> }
>
> BTW, Crimson doesn't like the files:
>
> Exception in thread "main" org.jdom.JDOMException: Error on line 24 of
> document
> file:/C:/tmp/jdom/formset/NT_SubscriberDetailsJPanel.xml: Element
> "titledborder"
>  allows no further input; "justification" is not allowed.
>
> -jh-
>
> Bart Read wrote:
> >
> > 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
> > >
> >
>
  ------------------------------------------------------------------------
> >                   Name: formset.dtd
> >    formset.dtd    Type: unspecified type (application/octet-stream)
> >               Encoding: quoted-printable
> >
> >                                      Name:
NT_SubscriberDetailsJPanel.xml
> >    NT_SubscriberDetailsJPanel.xml    Type: XML Document (text/xml)
> >                                  Encoding: quoted-printable
> >
> >                          Name: SAXParserDemo.java
> >    SAXParserDemo.java    Type: JavaScript Program
(application/x-javascript)
> >                      Encoding: quoted-printable
>




More information about the jdom-interest mailing list