如果字段为空,则dataSet.writeXml不写空标记C# [英] dataSet.writeXml does not write an empty tag if the field was empty C#
问题描述
我想使用.writeXml函数创建DataSet的XML.如果我的数据集中的条目为空,那么我想使用一个空标签而不是缺少标签:
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>
示例现在的样子:
<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!!
推荐答案
我认为您无法更改,因此如果它们为NULL,则将写入空值,因为NULL与空值不同.
但是,如果age的数据类型是字符串,则只需遍历数据集并将所有NULL更改为空字符串,然后再将其写入XML,即可获得想要的效果.
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.
这篇关于如果字段为空,则dataSet.writeXml不写空标记C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!