如何将多个数据集保存到xml文件 [英] How to save Multiple dataset to a xml file

查看:148
本文介绍了如何将多个数据集保存到xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何将多个数据集保存到单个xml中.
当我尝试下面的代码覆盖时,我只得到一个数据集值

Hi
How to save multiple dataset to a single xml.
when i try the below code its overwriting and i am getting only one dataset value

StreamWriter xmldoc = new StreamWriter(HttpContext.Current.Server.MapPath("123.xml"), false);
           ds.WriteXml(xmldoc);
           ds1.WriteXml(xmldoc);



谢谢



Thanks

推荐答案

如果您使用的是WriteXml方法,则后者的写操作将覆盖先前创建的文件的内容.

在将数据集写入文件之前,您是否可以合并数据集并写入合并的数据集.请参阅: DataSet.Merge [
If you''re using WriteXml method the latter write operation overwrites the contents of previously created file.

Before writing the dataset to the file, could you merge the datasets and write the merged dataset. See: DataSet.Merge[^]


这并不是不可能的;而是,这个问题没有完全指定.您尝试使用的方法将创建一些文本,这些文本永远不会代表格式正确的XML,这仅仅是因为两个XML的串联不是格式正确的XML.

您需要一些外部" XML模式,该模式将为两个或多个不同的XML提供一个容器,每个容器分别对应于两个或多个不相关的数据集的一部分(如果它们相关,则数据模型首先是错误的).这种模式是任意的.您无需指定要如何在XML容器中存储一个以上的数据集,因此可以通过许多类似的方式来实现.

整个想法很可能是错误的.如果在一个XML中需要两个数据集,为什么要使用两个不同的数据集?它们应该是一个统一的数据集.如果此简单原理与您的数据模型不符,则意味着您的数据模型首先是错误的.尽力证明我错了...

—SA
Not that it is impossible; rather, the question is not fully specified. The method you try to use will create some text which is never represents a well-formed XML, just because concatenation of two XMLs is not a well-formed XML.

You need some "outside" XML schema which would provide a container for two or more different XMLs each corresponding to the portion of two or more unrelated data sets (if they are related, you data model is wrong in first place). This schema is something arbitrary. You don''t specify how do you want to store more then one data sets in your XML container, so it can be done in many similar ways.

Most likely, the whole idea is wrong. If you need two data sets in one XMLs, why are two different data sets? They should be one united data set. If this simple principle is not in line with your data model, it means your data model is wrong in first place. Try to prove me wrong though…

—SA


为此,您必须编写一个用于动态生成xml文档的算法...请参阅如何编写xml格式表单数据集并使其在循环中
for this purpose you must write an alogrithm for generating xml document dynamically... see how to write xml formate form dataset and make it in loop


这篇关于如何将多个数据集保存到xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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