[jdom-interest] XML best-practices Q, RE:getChildren(string,ns) w/ default namespace

bob mcwhirter bob at werken.com
Thu Apr 18 13:00:33 PDT 2002


On Thu, 18 Apr 2002, Cory McIlroy wrote:

> In my application I would like to pass around a jdom Element and have methods be
> able to process the element.  This processing includes getting lists of children
> elements of some name.
> 
> throughout the entire XML doc in question, i use one default namespace.  so, i
> would like the various methods throughout the app to not have to worry about
> getting children of a particular ns, because there is only one.
> 
> One way to do this is of course to just not use a ns in my XML doc.
> and just use getChilren(String).  It would seem that this in some way violates
> good xml technique by using no_namespace.  

If JDOM supported a QName type of object, and allowed

	Element.getChildren(QName qname)

this would be a lot simpler:

public interface MyDocumenType
{
    public final static Namespace MY_DOC_NS = new Namespace(..)
    public final static QName DEVELOPER_NAME = new QName( "developer", MY_DOC_NS );
}

Then, in your application you could just do:

	element.getChildren( MyDocumentType.DEVELOPER_NAME )

Alas, we don't have a QName object...

	-bob




More information about the jdom-interest mailing list