将XML文件导入数据集 [英] Import XML file into dataset

查看:103
本文介绍了将XML文件导入数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我将以下xml文件导入数据集时遇到一些问题。


<?xml版本= QUOT; 1.0" standalone =" yes"?>

< logfile version =" 0.1.001" >

< log date =" 01.01.2005" time =" 12:01:59" username =" Mueller" level =

" Info" message =" 2">

< data order =" 1" caption =" Original Value" 60< / data>

< data order =" 2" caption =" Changed Value"> 80< / data>

< / log>

< / logfile>


如果我在Visual Studio中加载xml文件并查看数据页面,我会看到3

数据表。


1. logfile

2. log

3.数据


如果我选择表''log''它会显示存储在

标签''log''。

现在我可以扩展数据行并获得一个链接''日志数据''。

如果我点击这个链接我得到一个新表格,其中的信息存储在

标签''数据''中。


那很好,但我怎么能能够访问我的代码中的信息吗?

希望你理解我的问题并且可以帮助我。


祝你好运

Thomas

解决方案

Thomas,


XML数据集仅包含元素。你有一个XML文档。

你只能通过读取循环来导入数据集,同时使用

xmlnodereader获取属性属性来设置数据集中的那些

元素(项目)。


我希望这能给出一个想法


Cor

你好Cor,

Hmm Visual Studio在2层数据集中显示XML文件(不要知道
)如何更好地描述它。

第一层是一个表,其中包含来自标签的所有信息

''log''。

这意味着我有一个包含这样的行的表(根据我的

示例):


01.01.2005 12:01:59 Mueller Info 2


这行有一个加号,所以我可以扩展它。

如果我扩展行,我得到第二层的链接或更好的一秒

表,其中包含标签数据的信息。

问题是我无法访问我的代码中的第二层。

如果我使用数据集的readXml方法,我得到第一层(表)但是

不是第二层(表)。


希望你明白我的意思。


祝你好运

Thomas


Thomas,


您可以将其读作数据集。


要显示它,你可以使用设计器或这个简单的方法。

\\\

System.Data.DataSet ds = new System.Data.DataSet ();

ds.ReadXml(" XMLFile1.xml");

this.dataGrid1.DataSource = ds;

this.dataGrid1 .Expand(-1);

///


我希望这有帮助吗?


Cor

Hello all together,

I have a little problem importing the following xml file into a dataset.

<?xml version="1.0" standalone="yes"?>
<logfile version = "0.1.001" >
<log date = "01.01.2005" time = "12:01:59" username = "Mueller" level =
"Info" message = "2">
<data order="1" caption="Original Value">60</data>
<data order="2" caption="Changed Value">80</data>
</log>
</logfile>

If I load the xml file in Visual Studio and looks at the data page I see 3
data tables.

1. logfile
2. log
3. data

If I choose the table ''log'' it shows all information which are stored in the
tag ''log''.
Now I can expand a datarow and gets a link ''log data''.
If I click this link I get a new table with the information stored in the
tags ''data''.

That''s fine, but how can I get access to the information within my code?
Hope you understand my problem and can help me.

Best regards
Thomas

解决方案

Thomas,

And XML dataset contains only elements. You have an XML document.
That you can only import in a dataset by reading it looping while using the
xmlnodereader to get attribute by attribute to set those in the dataset
elements (items).

I hope this gives an idea

Cor


Hello Cor,

Hmm Visual Studio displays the XML file in a dataset with 2 layers (don''t
know how to describe it better).
The first layer is a table which contains all information from the tag
''log''.
That means I have a table which contains rows like this one (according to my
example):

01.01.2005 12:01:59 Mueller Info 2

This rows have a plus, so I can expand it.
If I expand the row, I get a link to the second layer or better a second
table which contains the information of the tag ''data''.
The problem is that I don''t have access to the second layer within my code.
I get the first layer (table) if I use the readXml-method of the dataset but
not the second layer (table).

Hope you understand what I mean.

Best regards
Thomas


Thomas,

You can read it as dataset.

To show it, you can use the designer or this simple method.
\\\
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml("XMLFile1.xml");
this.dataGrid1.DataSource = ds;
this.dataGrid1.Expand(-1);
///

I hope this helps?

Cor


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

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