struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Colin Sampaleanu <co...@Bspark.com>
Subject RE: [PROPOSAL] Integrating Struts with XML Data
Date Mon, 09 Oct 2000 16:07:51 GMT
> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: October 9, 2000 11:41 AM
> To: struts-dev@jakarta.apache.org
> Subject: Re: [PROPOSAL] Integrating Struts with XML Data
> 
> Colin Sampaleanu wrote:
> 
> > > -----Original Message-----
> > > From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> > > Sent: October 9, 2000 2:27 AM
> > > To: struts-dev@jakarta.apache.org
> > > Subject: [PROPOSAL] Integrating Struts with XML Data
> > >
> > > In the examples below, assume that a DOM object with the following
> > > structure is attached to the bean name "bean":
> > >
> > >     <a b="1" c="2">
> > >         <d e="3" f="4"/>
> > >         <d e="5" f="6"/>
> > >     </a>
> > >     <a b="7" c="8">
> > >         <d e="9" f="10"/>
> > >         <d e="11" f="12"/>
> > >     </a>
> > >
> > > Here's the proposal -- please let me know what you think:
> > > ...
> >
> > Looks quite usable.
> >
> > I have one question. What happens though if you have a 
> child element that
> > has the same name as an attribute in the parent element?
> >      <a b="7" c="8">
> >          <b x="0" y="1"/>
> >          <d e="9" f="10"/>
> >          <d e="11" f="12"/>
> >      </a>
> > According to your proposal, a.b would refer to the 
> attribute 'b' of element
> > 'a'. How do I refer to the child element 'b' of element 'a'?
> 
> With the proposal as originally stated, you cannot.  I'm not 
> sure how to fix
> that without breaking the transparency between accessing bean 
> properties and
> XML elements/attributes.
> 
> On the other hand, I'm not sure that it is going to be a 
> problem in practice.
> I would bet that most people will use element names like 
> "customer" or "order"
> and attribute names that match their bean property (or 
> database column) names
> -- clashes can happen, but are likely not to be common.
> 
> On the gripping hand (if you're a "Mote in God's Eye" fan 
> :-), we could extend
> the syntax to deal with this -- but I don't have any good 
> ideas for how off the
> top of my head.

Well, you could perhaps say that
  a.b
will get attribute 'b' of element a if b exists, or subelement 'b'
otherwise, but
  a.b[0]
will always get (the first) subelement 'b', since if you have an index you
are obviously refering to subelements.

As an aside, thinking a bit about this, I think that when you have something
like an XML configuration file, allowing
  <a b="z" /a>
or the alternative
  <a>
    <b>z</b>
  </a>
at the same time is very useful and very flexible, because the libray
reading the config deals with the different types, but w/regards to the
define tag it is potentially problematic that
  a.b
can return either a String or a DOM element, depending on whether or not
somebody forgot to put in an attribute, and the subelemnt exists. Presumably
these tags are being used for presentation of data that has been set up
properly, but if the xml is coming from any sort of more disconnected or
external source that's not a given. Also, what is the rule with regards to
Excetpions, on a.b, an Exception will be thrown only if 'b' doesn't exist as
either an attribute or subelement, right? It may be useful to have another
attribute specifying that on non-existence a null variable is defined
instead, or no variable at all, but no exception is thrown...


Mime
View raw message