如何将xml文件转换并解析为Dataset [英] How to convert and parse an xml file to Dataset
本文介绍了如何将xml文件转换并解析为Dataset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Web应用程序项目中,我使用以下代码加载xml文件:
In a web application project, I used the following code to load an xml file:
string url = "http://localhost:48677/Service1.svc/GetDataSet";
var webClient = new System.Net.WebClient();
string ReadData = webClient.DownloadString(url);
URL中发布的xml文件来源于数据集。它由两部分组成:第一部分是模式部分,如下所示:
The xml file posted in the URL is sourced a dataset. It consists of 2 parts: The 1st part is the schema part, like that:
<xs:schema xmlns=...>
...
</xs:element>
第二部分显示数据值,如下所示:
The 2nd part displays the data values, like that below:
<diffgr:difffram ...>
<NewDataSet xmlns="">
<MyData diffgr:id=...>
<ID>1</ID>
</MyDataSet>
.....
</NewDataSet>
</diffgr:diffgram>
我尝试过不同的方法尝试将ReadData转换/解析为DataSet,但没有成功。如果您知道,请告诉我如何实施此转换。谢谢。
I have tried different approaches to try to convert/parse the ReadData into a DataSet, but not successful. Please advise me how to implement this conversion if you know. Thanks.
推荐答案
最简单的方法是使用 xsd.exe [ ^ ]
您可以使用 cs-script [ ^ ]在运行时执行生成的代码。
最好的问候
Espen Harlinn
The simplest way to do this is by using xsd.exe[^]
You could then use something like cs-script[^] to execute the generated code at runtime.
Best regards
Espen Harlinn
检查这些,你会得到一些想法:
使用visual C#读取RSS源 [ ^ ]
通过C#读取XML [ ^ ]
将XML文件作为DataSet读取 [ ^ ]
Check these,you will get some idea:
Reading a RSS feed using visual C#[^]
Reading XML through C#[^]
Read XML file as DataSet[^]
To Ridoy:使用通过C#读取XML的方法,我可以很好地检索记录。谢谢。
Espen Harlinn:谢谢你的共鸣。
To Ridoy: Using the approach in Reading XML through C#, I can retrieve the records well. Thanks.
To Espen Harlinn: Thanks for your resonse.
这篇关于如何将xml文件转换并解析为Dataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文