Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

How can i remove namespace from the generated JAXB File ?

Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, here is my code:



And finnaly

i add "xjc:simple" in order to have @XMLRootElement, but an exception is raised: javax.xml.bind.UnmarshalException: unexpected element (uri:""

It didn't work correctly because i got this:@XmlRootElement(name = "Player", namespace = "")

Instead of just: @XmlRootElement(name = "Player")

How can i remove this "namespace" ?

Ranch Hand
Posts: 734
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[1] One thing you can try is to take out the external binding and make sure you do not use -npa switch for xjc. Then the schema will be compiled with namespace info contained in You can then manually delete or rename it with an extension other than .java. After doing that, I think you can safely unmarshal and marshal an xml document belonging to no namespace, as long as you don't validate it with the original schema.

[2] But what I don't understand the business logic here is that if you can do thing like [1], you can as well just retouch the schema(s) by eliminating the targetNamespace(s) and its ramifications for the purpose of adapting to the changing requirement in the sense that you now have to deal with incoming doc without namespace rather than having one originally.

[3] Given the assumption that you don't really want to touch the schema files and you don't want neither to do anything on the generated source .java files and nevertheless want to deal with the no namespace case, you can do it like this. You can write an XMLFilter implementation, mapping the startElement from no namespace to having the namespace coincident with the targetNamespace in the schema(s)... Make it stand between the sax reader and streaming to the unmarshaller. In that case all the addition measures are taken place in the application level leaving the compilation package and schema intact. This would be a cleaner approach in case [1] or [2] is not an option as they make modification to the package related to the schema compilation. This approach should work but I confess that it does sound a bit abstract until one makes their hands dirty in implementing it which is not overwhelmingly complicated for this shown simple document structure.
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic