Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HELP!: How to set default namespace in JDOM  RSS feed

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's driving me nuts. I need to generate something like this:

I tried to do this in JDOM by calling:

but I always receive an error "The namespace "xmlns="http://somethingsomething.com" could not be added as a namespace to "a": The namespace prefix "" conflicts with the element namespace prefix".

I've also tried sommenting out the addNamespaceDeclaration() line, which gets rid of the error, but doesn't put the xmlns attribute in my <a> element.

Any ideas?
 
Sheriff
Posts: 23451
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about this?
 
Philippe Desrosiers
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EXCELLENT! Thanks Paul. The only issue with this is that all the children of the <a> element now have a blank xmlns entry (like <b xmlns=""/>).

Yeah, I've read all the flame wars about lexical space versus informational space. I won't pour gasoline on that fire. I guess I'll just explicitly set the "default" namespace for all the child elements as well (wonder why they call it "default", then?)

Thanks again!
 
Paul Clapham
Sheriff
Posts: 23451
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Philippe Desrosiers:
I guess I'll just explicitly set the "default" namespace for all the child elements as well...

Yes, if you want them to be in the default namespace as well then you do have to declare them to be in the default namespace. If you don't do that, then they are... um... by... um... by default... in no namespace, so your output declares them thus. That's why you get the output you get.

You would get the same effect if you used a namespace with a prefix, by the way. So "default namespace" isn't a completely stupid name. Although I have to say, the default namespace is not my favourite XML feature either.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!