[jdom-interest] Nested namespaces and attribute prefixes - help?

Philip Nelson panmanphil at yahoo.com
Wed May 22 07:15:30 PDT 2002


Sorry, but I can't figure out exactly what you are trying to do or what is
going wrong.  Could you send some java code?  JDOM version?

Yes, your myattr attribute will be in the correct namespace if it is parsed
from a file.  If you are building the document in code, you will have to show
some examples for us.

--- Vanessa Williams <v.williams at acm.org> wrote:
> 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
> 
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com



More information about the jdom-interest mailing list