[jdom-interest] re: More changes

Robin Meade rmeade at outreach.hawaii.edu
Wed Jul 19 14:30:59 PDT 2000


Brett McLaughlin wrote:
> OK folks... some more food for thought:
> 
snip
> * What do people think about removing the convenience methods (like
> getIntContent()) on Element.java? Mark Diekhans pointed out that getting
> a default value from an attribute is quite different from getting one
> from an Element - typically, it means the Element is optional, or not
> there, but we also return the default if the /format/ is incorrect.  For
> example:
> 
> <port>yl7</port>
> 
> getPort(80); 
> 
> This currently returns 80, and should really result in an error - it
> masks problems in the underlying XML, which is generally a bad thing, I
> think. It is very hard to track this down, and different programs using
> different defaults can really obfuscate the document. So I'm actually
> for removing all the getXXXContent methods (but only on Element.java,
> not Attribute.java, where they make more sense).
> 
snip

1. I would remove the getXXX methods that take a 
default value, because, as you say, they mask 
probems with the underlying XML. I know in my 
applications, I'd always want data conversion 
errors to be treated as exceptions.

2. For consistency, I would have the getXXX methods on 
both Element and Attribute or on neither of them.

An example of where getXXX methods would be useful on 
elements is the Servlet 2.2 specification's web.xml 
file. It uses elements like this

      <param-name> name1 </param-name>
      <param-value> value2 </param-value>

Robin Meade



More information about the jdom-interest mailing list