users@jaxb.java.net

How to prevent xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

From: Markus Karg <karg_at_quipsy.de>
Date: Thu, 12 May 2011 08:44:50 +0200

As our XML output is highly dynamic, we are using JAXBElement instance
which we create on the fly shorty before marshalling.

Some of this dynamic elements can never have children, so we use the
following code:

 

new JAXBElement<Void>(new QName("http://www.myschema.com",
"my-local-name", "m"), Void.class, null)

 

This works pretty well, and renders like this:

 

<m:my-local-name xmlns:m="http://www.myschema.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

 

But what we like to have instead is:

 

<m:my-local-name xmlns:m="http://www.myschema.com"/>

 

Is there a simple way to tell JAXB that it shall not add xsi:nil?

 

Thanks!

Markus