保存没有 <NewDataSet> 的数据集 ds.WriteXml(...)标签? [英] Save a DataSet ds.WriteXml(...) without &lt;NewDataSet&gt; Tag?

查看:24
本文介绍了保存没有 <NewDataSet> 的数据集 ds.WriteXml(...)标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以毫无问题地将 XML 文件读取和写入数据集,但是如果我使用 ds.WriteXml("Testdata.xml") 保存数据集,则附加标签 <;NewDataSet>.......</NewDataSet> 生成.

I can read and write a XML File into a Dataset with no problems, but if I save the DataSet with ds.WriteXml("Testdata.xml") a additional Tag <NewDataSet>.......</NewDataSet> is generrated.

是否可以抑制这种标签生成?

Is it possible to supress this Tag genaration?

推荐答案

一个数据集可以包含多个表,一个有效的 XML 文件必须包含一个单一的根节点,这就是它被包装在这个节点中的原因.您可以在创建 DataSet 时指定根节点的名称:

A dataset can contain multiple tables and a valid XML file must contain a single root node that's why it is wrapped in this node. You could specify the name of the root node when creating the DataSet:

var ds = new DataSet("root");

但如果您想删除它,您可以先将数据集加载到 XDocumentXmlDocument 然后提取您需要的节点并保存到文件中.

but if you want to remove it you could first load the DataSet into a XDocument or XmlDocument and then extract the node you need and save it into a file.

这篇关于保存没有 <NewDataSet> 的数据集 ds.WriteXml(...)标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆