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 不返回空结果
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
