DataSet.GetXml not returning null results(DataSet.GetXml 不返回空结果)
问题描述
每当我使用 DataSet.GetXml 将 DatSet 转换为 XML 时,任何 null 值都会被忽略,所以,我期望这样:
whenever I convert a DatSet into an XML with DataSet.GetXml, any null value is ignored, so, where i expect this:
<value1>a</value1>
<value2></value2>
<value3>c</value3>
我得到了这个:
<value1>a</value1>
<value3>c</value3>
有什么快速而肮脏的方法来处理这个问题吗?谢谢
Any quick and dirty way to handle this? Thanks
我认为解决方案是使用 WriteXml.谁能给我提供一个使用它而不写入文件但像 GetXml 一样获取字符串的示例?谢谢
I think a solution would be using WriteXml. Could anyone provide me with a sample of using it WITHOUT writing to a file but getting a string just like GetXml does? Thanks
推荐答案
这很好用:
//convert to xml with the DataSet schema:
StringWriter writer = new StringWriter();
ds.WriteXml(writer, XmlWriteMode.WriteSchema);
string xml = writer.ToString();
//Convert from xml to DataSet:
StringReader stringReader = new StringReader(response);
DataSet ds = new DataSet();
ds.ReadXml(stringReader);
这篇关于DataSet.GetXml 不返回空结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DataSet.GetXml 不返回空结果
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 将数据集转换为列表 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
