[jdom-interest] Deprecating hasChildren()
Jason Hunter
jhunter at servlets.com
Sat May 11 11:32:33 PDT 2002
if (elt.getChildren().size() == 0)
-jh-
Elliotte Rusty Harold wrote:
>
> At 3:50 AM -0400 5/11/02, cvs at jools.org wrote:
> >Deprecated elt.hasChildren() because it's not a performance optimization
> >anymore. This helps simplify the most complicated class around.
> >
>
> I have one use-case for that method that doesn't involve
> optimization. Consider this street element:
>
> <street>135 Airline Highway <apartment>2B</apartment></street>
>
> getText() returns "135 Airline Highway ". The content in the child
> apartment element is completely lost. Before you can reliably use any
> of the getText()/getTextTrim()/ getTextNormalize() methods you need
> to be very sure that the element does not have any child elements.
> One way to do this is to test with hasChildren() before invoking the
> text getter. For example,
>
> if (!element.hasChildren()) {
> String result = element.getText();
> // work with result
> }
> else {
> // do something more complex
> }
> --
>
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> | The XML Bible, 2nd Edition (Hungry Minds, 2001) |
> | http://www.cafeconleche.org/books/bible2/ |
> | http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/ |
> +----------------------------------+---------------------------------+
> | Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
> | Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
> +----------------------------------+---------------------------------+
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list