[jdom-interest] Accessing Child Elements
David W. Smiley
dsmiley at mitre.org
Wed Sep 6 12:49:15 PDT 2000
> It's been said that a JDOM tree can be unvaildated, badly formed and in
> all sorts of intermediate states - this is undoubtedly useful,
> programatically, but at the same time the classes and objects making up
> the api have to represent something beyond 'an oddly constrained
> tree/digraph with funny node names' so some contracts have to be
> enforced and some amount of useful default behaviour has to be provided.
True; although AFAIK I don't think JDOM as it exists now can become
invalidated. Of course that change I mentioned previously that checks
to make sure that an element being added isn't an ancestor would have to
be added.
> Doing this and keeping the API simple, flexible and easy to understand,
> getting the balance right, can be quite tricky (and contentious and
> fun).
>
> I'd argue that the current code 'works' but is wrong. It works well
> enough for outputting the XML and getting the correct namespace scoping
> but it doesn't _model_ the way namespaces actually work and that's
> what's confusing.
> Element.getNamespace() should tell you what namespace an element is
> _currently_ in, a new method is needed to query the namespace an element
> was explicitly declared in.
What does that give you though? I think a JDOM element should either
have a namespace set (explicit namespace) OR it should inherit the
namespace of the parent (implied namespace). The only issue is making
sure that the namespace be maintained as an element is added / removed /
cloned.
...
> - if an element is in the default namespace getNamespace should
> recursively find the enclosing explicitly declared namespace by
> walking up the tree. This models the way namespaces are 'lexically
> scoped' in XML.
...
From what I understand about XML namespaces, they aren't lexically
scoped which is why "boston" has the default namespace instead of "us"
in this example:
<us:massachusetts>
<boston>
</us:massachusetts>
See the FAQ: http://www.oasis-open.org/cover/NamespacesFAQ20000313.html
However, I do believe that JDOM, an api, should employ namespaces in a
way that /is/ lexically scoped... so that when you add "boston" to its
parent without specifying a namespace, you'd get "us:boston" instead.
-- David Smiley
More information about the jdom-interest
mailing list