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 不返回空结果


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01