[xsd-users] Setting xsi:nil=true
Boris Kolpackov
boris at codesynthesis.com
Wed Jun 27 07:48:36 EDT 2007
Hi Steinar,
Steinar Rune Eriksen <steinar at viz.no> writes:
> I am trying to use cxx_tree to generate an element of the type, example
> <n1:MemAddress2 xsi:nil="true"/> How do I do that?
Nillable elements are very rarely used (you are the first person who asked
for this) and as a result are not directly supported by XSD. There is,
however, a number of ways to work around this limitation.
The easy way is only suitable if the MemAddress2 can have an empty value.
In other words, the following is legal:
<n1:MemAddress2></n1:MemAddress2>
If that's the case then you can use the generated code as is. The
generated code will map both the empty value and the nil value cases
to the same instance with empty value (XSD-generated code simply
ignores the xsi:nil attribute). You can distinguish between the two
by either using the DOM association feature or using type customization,
as described below.
The more elaborate way, that will work for any type, is to customize
the generated type for MemAddress2 and to check for the xsi:nil
attribute in the parsing constructor. For more information on type
customization see:
http://wiki.codesynthesis.com/Tree/Customization_guide
For an idea about customizing the parsing constructor see the wildcard
example in examples/cxx/tree/custom/wildcard/.
hth,
-boris
More information about the xsd-users
mailing list