tags:

views:

311

answers:

3

I have an application with a REST style inerface that takes XML documents via POST from clients. This application is written in Java and uses XML beans to process the posted message.

Now, 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 CML parser to barf.

A: 

What about <value xsi:nil="true"></value>? That's what's in the spec.

aaronsw
+1  A: 

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?

Owen
Given that the `<value>` element is typed as `xs:string`, using `<value/>` would give it a value of an empty string, rather than a null value. But it might be that an empty string will do.
JeniT
JeniT: your prediction was exactly right. I received an empty string when I tried out this suggestion.
Rangachari Anand
A: 

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.

JeniT
This was exactly the information I needed. I followed your instructions and added the attribute for the xsi namespace and was then able to get the parser to accept and validate the posted XML document. Nice!
Rangachari Anand