users@jaxb.java.net

Re: Marshalling list types

From: jon gold <dev_at_samizdatdigital.org>
Date: Mon, 11 Oct 2004 11:26:08 -0700

hi -- i'm not too familiar with it, but i've seen people on this list
discuss the use of an attribute 'nillable', which i believe allows you
to set things to null. does it make sense to try something like (you
probably will need to confirm the syntax somewhere):

     <attribute name="error" type="errorType"
                use="optional" nillable="true"/>


incidentally, for your second question (what to do if the schema can't
be changed), you could pipe the output of your marshaller through either
an xslt transform or a sax result + transform which listens for the
appropriate empty attributes and just removes them.

jon

Jörg Meister wrote:
> Hi all,
>
> i have a problem marshalling an attribute, that helds a list like the xml
> schema below.
>
> <complexType name="Header">
> <attribute name="error" type="errorType" use="optional"/>
> </complexType>
> <simpleType name="ErrorType">
> <list itemType="ErrorNrType"/>
> </simpleType>
> <simpleType name="ErrorNrType">
> <restriction base="string">
> <length value="9"/>
> <pattern value="[A-Z]{2}([0-9]|[A-Z]){7}"/>
> </restriction>
> </simpleType>
>
> Everything went fine, if the list helds data. If the attribute helds no
> data, the output of the marshaller looks like
>
> <myElement error=""/>
>
> But this will lead to an error during validation. Looking at the generated
> code by the xjc, i have seen, that is is impossible to set the list to NULL.
> Even the unset method will be no help, because the attribute will be set to
> an empty list, if unset() will be called.
> "error" is an optional attribute. Is it possible that the marshaller will
> NOT print the attribute if the list contains no data? If not, want could be
> done to get a valid output (it is not possible to change the schema)?
>
> Since
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net