XML Serialization

R

RJN

Hi

I'm using XML Serialization for serializing an object. I read a set of
records from the database and populate the members of the object if the
value is not null. eg., I have an Employee object which has its members
Id,name and address. If the Id is not null then I will populate its
value from that I got from the databse. When I serialize the object , I
find that xml structure will always have the Id column either with the
actual value or with value 0 if the value is Null in the databse.
<employees>
<employee><Id>111</Id><name>aaa</name></employee>
<employee><Id>0</Id></name></employee>
</employees>

My feeling is this is the default behaviour of xml serializer for data
types int, boolean and date and will have a value 0,0001-01-01 and false
as default values respectively.

I cannot set the property <XmlElement(IsNullable:=True)> for value
types. Is there any way where I can avoid serializing types of int,date
and boolean when they have null values in the database.

Regards

RJN



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
G

Guest

Why don't you use dataSet, put info into dataSet, use DataSet.WriteXml will meet your requirment.
 
R

RJN

I can't use dataset as there is a hierarchy within the objects. i.e.,
Employee will have a list of addresses etc..
something like this.

<Employee>
<Id></Id>
<Addresses>
<Address></Address>
</Addresses>
</Employee>

So I construct the object graph and then serialize the object

Rjn

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top