XML:使用XML作为数据源的最佳方法 [英] XML: Best ways to work with XML as datasource

查看:76
本文介绍了XML:使用XML作为数据源的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我目前需要一些建议,以对我的新XML编程(VB 2005)充满信心:

1.我打算为每个表"提供一个XML,而不是将表"合并到几个XML文件中.这是明智的做法,最终得到40个XML文件吗? (如果我使用XSD进行验证,那么我还会得到40个XSD文件吗?)
我现在对此有答案:选项1是使用带有内联架构信息的xml.这意味着每个XML文件都不需要xsd文件.似乎对于每个表"来说,都会有一个xml文件供我使用;但是其他程序员将几个表合并到一个xml文件中,但我不希望那样做.

2.我创建了一个XSD来反映我的表"和关系/约束,但是我缺少将其链接到相关XML文件的方法.现在,当我将对象从XSD生成的数据集中拖到窗体上时,它会创建datasetbindingsourcebindingnavigator的实例,但是它们是空的;这意味着我仍然不知道如何链接生成的dataset和XML文件,而XML文件应该是数据的来源.我想这就是为什么它也不会像数据库数据集那样在表单上创建tableadapter的原因. 我发现可以先使用ReadXMLSchema,再使用ReadXML.不幸的是,当我仅使用ReadXML时,我会用数据填充数据集,但是如果我同时编写两者,则会用表和结构填充数据集,但没有数据.

Hi,

I currently need a little advice to be confident with my new XML programming (VB 2005):

1. I intend to have an XML for each of my ''tables'' rather than combine ''tables'' in a few XML files. Is this the sensible thing to do, thus end up with say 40 XML files? (If I am using XSD for validation, I also end up with 40 XSD files?)
I feel I have the answer to this now: Option 1 is to have xml with inline schema information. This means no need for xsd file for each xml file. It seems though that for each ''table'' there will be an xml file for me; other programmers however combine several tables in an xml file but I prefer not to do it that way.

2. I have created a single XSD to reflect my ''tables'' and relationships/constraints, but I am missing a way of linking it up to the relevant XML files. Right now, when I drag an object from the dataset generated from the XSD to a form, it creates the instances of dataset, bindingsource and bindingnavigator, but they are empty; which means I still dont know how to link this generated dataset and the XML files, which should be the source of the data. I guess this is why it also doesn''t create a tableadapter on the form as would a database dataset.
I have found out that I can use ReadXMLSchema followed by ReadXML. Unfortunately, when i use ReadXML only, i get to fill the dataset with data, but if i write the two concurrently I fill the dataset with the tables and structure but no data.

mainDataSet.ReadXmlSchema("CustomerOrders.xsd")
mainDataSet.ReadXml("AppData\Customers.xml")


第二行单独提供数据,但当它以ReadXMLSchema开头时不提供数据?

我已经看到了一个可以在其中运行的Web应用程序的示例,但是我不知道为什么我的数据没有填充!我感觉好近...

您在这里的建议将极大地推动我前进.

对于那些寻求如何从XML的XSD生成可视数据集的人,请查看以下链接: http://blogs.vbcity. com/mcintyre/archive/2006/09/26/6248.aspx [ ^ ]


the second line alone supplies the data, but not when it is preceded by ReadXMLSchema???

I have seen an example of web application where it works but i can''t figure out why mine isn''t filling the data! I feel so close...

Your advice here will push me forward a great deal.

For those looking for how to generate the visual dataset from an XML''s XSD, please check out this link: http://windev.wordpress.com/2007/03/05/tips-and-tricks-generate-typed-dataset-from-an-xsd-file-in-visual-studio-2005/[^]

A good example of CRUD with XML is also available here: http://blogs.vbcity.com/mcintyre/archive/2006/09/26/6248.aspx[^]

推荐答案

DataSet类具有ReadXmlWriteXml方法(如DataTable).

如果您真的必须为此使用XML,为什么不将数据加载到DataSet中,使用它,然后最后将其写回XML?
The DataSet class has ReadXml and WriteXml methods (as does the DataTable).

If you really must use XML for this why not load the data into a DataSet, work with it, then write it back out to XML at the end?


我仍然没有弄清楚为什么xmlreadschema xmlread 无法为我工作,但这是我现在所做的:

创建一个循环,用每个xml文件填充一个临时数据集.在循环中,将临时数据集合并到所需的dataset
I still didnt figure out why the xmlreadschema and xmlread cannot work for me but this is what i did for now:

create a loop that fills a temporary dataset with each xml file. within the loop merge the temporary dataset to the required dataset!


这篇关于XML:使用XML作为数据源的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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