C#:DataSet.readXML(“filepath”)如何与对象内对象中的对象的XML文件配合使用? [英] C#: How does DataSet.readXML( "filepath" ) work with my XML file that has objects within objects within objects?
问题描述
我有一个格式如下的xml文件:
< items>
< item>
< itemProperty1> Propeterty1< / itemProperty1>
< itemProperty2> Propeterty2< / itemProperty2>
< propertyWithSubProperties1>
< subprop1> subProp1< / subProp1>
< subprop2> subProp2< / subProp2>
< depthPropertyWithSubProperties1>
< depthSubProperty1> data< / depthSubProperty1>
< depthSubProperty2> data2< / depthSubProperty2>
< / depthPropertyWithSubProperties1>
< / propertyWithSubProperties1>
< / item>
...更多项目
< / items>
我试图使用c#中的数据集读取这个数据文件,如下所示:
DataSet dataSet = new DataSet();
dataSet.ReadXml(fileName);
我可以访问前两个项目没有这样的问题:
firstProperty = dataSet.Tables [0] .Rows [i] [0] .ToString();
secondProperty = dataSet.Tables [0] .Rows [i] [1] .ToString();
但是,我完全不知道如何获取其他项目中的信息,因为他们是一级或更深。我通常的谷歌搜索没有任何用途。
您的 DataSet
将包含三个表:
-
dataSet.Tables [0]
:
列itemProperty1
,itemProperty2
和item_Id
。 -
dataSet.Tables [1]
:
列subProp1
,subProp2
,propertyWithSubProperties1_Id
和item_Id
/ p> -
dataSet.Tables [2]
:
列deepSubProperty1
,deepSubProperty2
和propertyWithSubProperties1_Id
。
表[0]
链接到表[1]
使用自动生成的 item_Id
列。
表[1]
使用自动生成的 propertyWithSubProperties1_Id
列链接到 Tables [2]
p>
I've got an xml file formatted like this:
<items>
<item>
<itemProperty1>Propeterty1</itemProperty1>
<itemProperty2>Propeterty2</itemProperty2>
<propertyWithSubProperties1>
<subprop1>subProp1</subProp1>
<subprop2>subProp2</subProp2>
<deeperPropertyWithSubProperties1>
<deeperSubProperty1>data</deeperSubProperty1>
<deeperSubProperty2>data2</deeperSubProperty2>
</deeperPropertyWithSubProperties1>
</propertyWithSubProperties1>
</item>
...More items
</items>
I'm trying to use a dataset in c# to read in this datafile like this:
DataSet dataSet = new DataSet();
dataSet.ReadXml(fileName);
I can access the first two items no problem like this:
firstProperty = dataSet.Tables[0].Rows[i][0].ToString();
secondProperty = dataSet.Tables[0].Rows[i][1].ToString();
But nothing I'm completely baffled as to how to get at the information in the other items because they are a level or more deeper. My usual google searches turn up nothing of use.
Your DataSet
will contain three tables:
dataSet.Tables[0]
:
ColumnsitemProperty1
,itemProperty2
anditem_Id
.dataSet.Tables[1]
:
ColumnssubProp1
,subProp2
,propertyWithSubProperties1_Id
anditem_Id
.dataSet.Tables[2]
:
ColumnsdeeperSubProperty1
,deepSubProperty2
andpropertyWithSubProperties1_Id
.
Tables[0]
is linked to Tables[1]
using the auto-generated item_Id
columns.
Tables[1]
is linked to Tables[2]
using the auto-generated propertyWithSubProperties1_Id
columns.
这篇关于C#:DataSet.readXML(“filepath”)如何与对象内对象中的对象的XML文件配合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!