[jdom-interest] adding default attributes

Bart Read bart at wdi.co.uk
Thu Jul 19 03:58:47 PDT 2001


Hi Guys,


Had a similar problem myself a few weeks back.  You need to use the
org.jdom.SAXBuilder class with validation switched on, and therefore you
obviously need to stick a !DOCTYPE element at the top of your XML document
that points to the DTD.  Note though that attributes with default values
have these default values assigned after other attributes have been parsed
in, so they appear after other attributes in the List that the
getAttributes() method returns (class org.jdom.Element).

Hope this helps,


=================================
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: "Szegedi, Attila" <szegedi at scriptum.hu>
To: "'Christian Knorr'" <christian.knorr at gmx.de>; "'jdom-interest'"
<jdom-interest at jdom.org>
Sent: Thursday, July 19, 2001 10:30 AM
Subject: RE: [jdom-interest] adding default attributes


> Documentation for SAX2 ContentHandler.startElement() method states that
>
> "Note that the attribute list provided will contain only attributes with
> explicit values (specified or defaulted): #IMPLIED attributes will be
> omitted."
>
> This clearly means that if there is a DTD, defaulted attributes should
> appear, otherwise it is a bug.
> Attila.
>
> > -----Original Message-----
> > From: jdom-interest-admin at jdom.org
> > [mailto:jdom-interest-admin at jdom.org]On Behalf Of Christian Knorr
> > Sent: Thursday, July 19, 2001 9:28 AM
> > To: jdom-interest
> > Subject: [jdom-interest] adding default attributes
> >
> >
> > Hi,
> >
> > I am looking for a convenient way to add default attribute
> > values (like
> > the following in DTD:
> > <!ATTLIST Frameset Orientation (horizontral | vertical ) 'vertical' >
> > ) to a JDOM-tree like SAXBuilder does when reading the document from a
> > file.
> >
> > I tried to serialize the document to a string and read it again with
> > SAXBuilder, but in this case the default attributes are not
> > automatically added when reading.
> >
> > My test code is the following:
> >
> >       XMLOutputter xo = new XMLOutputter();
> >       StringWriter sw = new StringWriter();
> >       xo.output(doc, sw);
> >       SAXBuilder sb = new SAXBuilder();
> >       sb.setValidation(true);
> >       doc = sb.build(new StringReader(sw.toString()));
> >
> > The DTD is definitly used for validation but not for adding default
> > attribute values. Is this a bug or is there another way to accomplish
> > this?
> >
> > Christian
> > _______________________________________________
> > To control your jdom-interest membership:
> > http://lists.denveronline.net/mailman/options/jdom-interest/yo
> uraddr at yourhost.com
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
>
> ---------- 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




More information about the jdom-interest mailing list