Skip to main content

How to customize JAXB to not generate duplicate xmlns:xs="http://www.w3.org/2001/XMLSchema"?

1 reply [Last post]
alecswan
Offline
Joined: 2003-11-10
Points: 0

Hello,

I am using JAXB 2.2 to convert annotated Java objects to XML and back. I do not use XSD schema. Each element in the generated XML has xmlns:xs="http://www.w3.org/2001/XMLSchema" attribute. These attributes take up a lot of space and make XML difficult to read.

How can I configure JAXB to prevent generation of those attributes for each element?

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ivitoria
Offline
Joined: 2010-11-24
Points: 0

Hello,
You must add a file named package-info.java at your POJOs package level. In this sample, the package is com.mycompany.samples.bean:
-------------
@javax.xml.bind.annotation.XmlSchema(xmlns = { @javax.xml.bind.annotation.XmlNs(prefix = "xsi", namespaceURI = "http://www.w3.org/2001/XMLSchema-instance"), @javax.xml.bind.annotation.XmlNs(prefix = "xs", namespaceURI = "http://www.w3.org/2001/XMLSchema") })
package com.mycompany.samples.bean;
------------

Cheers,
Ivan