[jdom-interest] Patch: Element.getChildren(Namespace)

Jason Hunter jhunter at collab.net
Tue Feb 20 19:37:36 PST 2001


> > Could you please give some specific use cases for this?
> 
> Sure,
> 
> You have a type of document that looks like this ("http://x.org/" if your
> namespace).
> 
>         <x:a xmlns:x="http://x.org/">
>             <x:b />
>             <x:c />
>             <x:b />
>             ...
>         </x:a>
> 
> (e.g., 'a' contains a mixture of 'b' and 'c')
> 
> Someone else creates one of these documents, but they annotate it with some
> other elements in there namespace and then send it to you:
> 
>         <x:a xmlns:x="http://x.org" xmlns:y="http://y.org">
>             <x:b />
>             <y:p />
>             <x:c />
>             <y:q />
>         </x:a>
> 
> in the code that processes elements of type a, you only want to process the
> children in your namespace, you can't possibly handle the other elements so
> you either write the loop quoted above, or you use getChildren(Namespace):
> 
>         Iterator itr = currentElement.getChildren(myNamespace).iterator();
>         while (itr.hasNext()) {
>           Element elem = (Element)itr.next();
>           ...
>         }
> 
> I admit that getChildren(Namespace) will only save you two lines of typing,
> but it seems to me that those two lines will be written many times.

Anyone else believe they would find this useful?

-jh-



More information about the jdom-interest mailing list