[jdom-interest] Nested namespaces and attribute prefixes - help?
Vanessa Williams
v.williams at acm.org
Tue May 21 20:53:30 PDT 2002
Hi, I've been using JDOM a little, but not extensively. For my purposes it's
been fine so far. Unfortunately, I find myself stumped, and after looking
through the list archives, feel the need to ask for help.
Let's say I have a document like this:
<a:operation xmlns:a="http://www.someplace.org/myschema.xsd">
<somedata a:myattr="lalala">
...
</somedata>
</a:operation>
So the root element's namespace prefix is "a" and namespace URI is as shown.
The <somedata> element has no namespace at all; however the attribute
"myattr" shares the namespace whose prefix is "a". As I understand it, that
namespace declaration is still "in scope" and this is valid XML (please
correct me if I'm wrong!).
Now when I parse the document and use getChild(0) on the root to retrieve
the <somedata> element, the namespace for the attribute seems to disappear.
When I print the returned child Element (using
XMLOutputter.output(Element)), it looks like this:
<somedata myattr="lalala">
...
</somedata>
What I really need back is:
<somedata xmlns:a="http://www.someplace.org/myschema.xsd" a:myattr="lalala">
...
</somedata>
I tried using getNamespace() on the parent element and then adding that
namespace declaration to the element (an act of desperation), and what I got
back in that case was:
<somedata xmlns:a="http://www.someplace.org/myschema.xsd" myattr="lalala">
...
</somedata>
The declaration was indeed added, but the attribute had still lost its
association with it.
I've seen several postings about namespace usage, but none seem to apply to
this particular case. Can anyone provide any suggestions? I think I must be
missing something basic.
Thanks in advance,
Vanessa
v.williams at acm.org
More information about the jdom-interest
mailing list