• 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

JAXB and XML default namespace issue.

 
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using JAXB 2.1.12 version to generate an xml.

Now my xml appears as:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<first_volume xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.company.com/firstVolume/1.0 first.xsd"
...........................>

I want it to be like the following

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<first_volume xmlns="http://www.company.com/firstVolume/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.company.com/firstVolume/1.0 first.xsd"
...........................>


I am not able to produce the default xmlns attribute, Please help...
Thanks in advance.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind guys, found the answer.
 
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
Excellent! Would you mind sharing the answer here, so that future victims of the problem can benefit?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry.. here it is...

Everytime the JAXB object model is generated from the schema... it generates the "package-info.java" class, sometimes it generates the annotation for the default namespace...but sometimes it doesn't (dependent on the schema)

Adding the following annotation just above the package declaration gives us the default namespace attribute in the XML.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also facing the same issue ...but i tried everything ...like creating package-info.java file ... and tried NamespacePrefixMapper ...but i am unable to get the default prefix ...i am using java1.7
 
Greenhorn
Posts: 3
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can generate namespace information using @XmlSchema annotation. It is a package level annotation which should be used in a special file called as "package-info.java". Shown below is how you can use it:


To generate the schema location information we can use the JAXB marshaller's JAXB_SCHEMA_LOCATION property as shown below:


For detailed information and working examples follow the link:
 
reply
    Bookmark Topic Watch Topic
  • New Topic