tags:

views:

206

answers:

1

Hi there,

I want to create a XML of my DataSet using the .writeXml-function. If an entry in my DataSet was null, i would like to have an empty tag instead of a missing tag:

example how it should look like if John had no age:

  <MyDataSet>
    <ID>8613458</ID>
    <AW_ID>37534778</AW_ID>
    <NAME>Peter</NAME>
    <AGE>22</AGE>
  </MyDataSet>
  <MyDataSet>
    <ID>8613459</ID>
    <AW_ID>37534779</AW_ID>
    <NAME>John</NAME>
    <AGE></AGE>
  </MyDataSet>

example how it looks like right now:

  <MyDataSet>
    <ID>8613458</ID>
    <AW_ID>37534778</AW_ID>
    <NAME>Peter</NAME>
    <AGE>22</AGE>
  </MyDataSet>
  <MyDataSet>
    <ID>8613459</ID>
    <AW_ID>37534779</AW_ID>
    <NAME>John</NAME>
  </MyDataSet>

Do you know what I need to do? Thanks for your help!!

+1  A: 

I don't think you can change so that it writes empty values if they are NULL since NULL is different from empty.
However, if the datatype of age is a string, just go through the dataset and change any NULLs to empty strings before writing it to XML and you'd get the effect you want.

ho1
Thanks. Didn't work in my case, because I had no strings.But I found another solution for my problem:instead of using .WriteXml(sting fileName) I made use of .WriteXml(string fileName, XmlWriteMode WriteSchema)-> this result is, that DBNull was turned into "0" instead of a missing tag
Christoph