Wolfgang,
thanks a lot for your kind help.
Unfortunately I already knew this workaround, and I want to prevent
getting that empty text() node if any possible.
Thanks
Markus
From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Sent: Donnerstag, 12. Mai 2011 09:17
To: users_at_jaxb.java.net
Subject: Re: How to prevent xsi:nil="true"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
If this is acceptable to you:
<m:my-local-name xmlns:m="
http://www.myschema.com"></m:my-local-name>
you can do
JAXBElement<String> xe =
new JAXBElement<String>(new QName("
http://www.myschema.com",
"my-local-name", "m"), String.class, "");
Obviously, this does have a text() child, since xsi:nil is gone. But
this is what you want, isn't it ;-)
-W
On 12 May 2011 08:44, Markus Karg <karg_at_quipsy.de> wrote:
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