Reputation: 7102
I've created an asp.net web service for a client of ours which returns multiple List
objects containing complex types. The client has been receiving data just fine.
He has noticed though that not all the tags are there all the time. If, for example, I return 3 objects in my list, objects A B and C. and C is null when I return it. It will show:
<A>data</A>
<B>data</B>
When I would like it to show the following:
<A>data</A>
<B>data</B>
<C/>
Or at least:
<A>data</A>
<B>data</B>
<C></C>
Basically, I want the structure of the XML to remain the same regardless of what data is available and what data is null.
Any suggestions?
Thanks a lot!!
Upvotes: 1
Views: 4062
Reputation: 3517
Soap spec. states:
A NULL value or a default value MAY be represented by omission of the accessor element. A NULL value MAY also be indicated by an accessor element containing the attribute xsi:null with value '1' or possibly other application-dependent attributes and values.
Unfortunately for You MS has chosen first option for this situation.
On the other hand you could not make NULL value like this:
<C></C>
because how would You differ between empty string and null?
This option
<C/>
looks promising. I'm guessing your service uses XMLSerializer to serialize your data. Check this post. Maybe you can implement IXMLSerializable
for your object and provide custom xml for your data.
Upvotes: 3