This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes JAXB and XML default namespace issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB and XML default namespace issue." Watch "JAXB and XML default namespace issue." New topic

JAXB and XML default namespace issue.

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 281


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="" xsi:schemaLocation=" first.xsd"

I want it to be like the following

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<first_volume xmlns="" xmlns:xsi="" xsi:schemaLocation=" first.xsd"

I am not able to produce the default xmlns attribute, Please help...
Thanks in advance.

Time is what we want the most, but what we use the worst. -- William Penn
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 281

Nevermind guys, found the answer.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Excellent! Would you mind sharing the answer here, so that future victims of the problem can benefit?
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 281

Sorry.. here it is...

Everytime the JAXB object model is generated from the schema... it generates the "" 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.

Girishkumar chellangi

Joined: Apr 17, 2014
Posts: 3
I am also facing the same issue ...but i tried everything creating file ... and tried NamespacePrefixMapper ...but i am unable to get the default prefix ...i am using java1.7
Ashutosh Meher

Joined: Oct 11, 2015
Posts: 2

We can generate namespace information using @XmlSchema annotation. It is a package level annotation which should be used in a special file called as "". 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:
I agree. Here's the link:
subject: JAXB and XML default namespace issue.
It's not a secret anymore!