• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB and XML default namespace issue.

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Nevermind guys, found the answer.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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.

 
Girishkumar chellangi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Ashutosh Meher
Greenhorn
Posts: 3
Java Spring
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic