users@jaxb.java.net

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

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 12 May 2011 09:16:52 +0200

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
>