What XML do I send for a field thats declared as nillable?
Question
I have an application with a REST style interface that takes XML documents via POST from clients. This application is written in Java and uses XML beans to process the posted message.
The XML schema definition for a field in the message looks like this:
<xs:element name="value" type="xs:string" nillable="true" />
How do I send a null value that meets this spec?
I sent <value xsi:nil="true" />
but this caused the XML parser to barf.
Solution
That's the right way of sending a nil value (assuming that the default namespace and the xsi
namespace are set to the correct values, namely "http://www.w3.org/2001/XMLSchema-instance"
for xsi
.) so it looks like you might have come up against a bug in the CML parser you're using. What's the error message?
You might try using xsi:nil="1"
or using separate open and close tags (<value xsi:nil="true"></value>
) to try working around the bug.
OTHER TIPS
What about <value xsi:nil="true"></value>
? That's what's in the spec.
In the past when I've had XML elements that were null I could either not include them or send them empty so, in your case it'd be:
<value />
Have you tried that?