• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HELP!: How to set default namespace in JDOM

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about this?
 
Philippe Desrosiers
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic