请...通过特定节点循环的示例代码 [英] Please ... example code due on looping though specific nodes

查看:63
本文介绍了请...通过特定节点循环的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对XML很陌生,昨天发布了一个示例代码请求。

不幸的是,我没有很好地解释我的内容

对于。以下是该文件的一小部分示例:


<记分板>

<事件>

<事件ID =001212名称= QUOT; EventName1" />

<事件ID =" 001213"名称= QUOT; EventName2" />

<事件ID =" 001214"名称= QUOT; EventName3" />

<事件ID =" 001215"名称= QUOT; EventName4" />

< / Events>

< EventTypes>

< EventType ID =" 01" SingleGame = QUOT;真"名称= QUOT; EventName1" />

< EventType ID =" 02" SingleGame = QUOT;真"名称= QUOT; EventName2" />

< EventType ID =" 03" SingleGame = QUOT;真"名称= QUOT; EventName3" />

< EventType ID =" 04" SingleGame = QUOT;真"名称= QUOT; EventName4" />

< EventType ID =" 05" SingleGame = QUOT;真"名称= QUOT; EventName5" />

< EventType ID =" 06" SingleGame = QUOT;真"名称= QUOT; EventName6" />

< EventType ID =" 07" SingleGame = QUOT;真"名称= QUOT; EventName7" />

< / EventTypes>

<团队>

<团队ID =" 11"市= QUOT; City1"名称= QUOT;名1" City =" City1"

Nickname =" nickname1" Conference =" Conference1"

< Player ID =" 91" />

< Player ID =" 190" />

< Player ID =" 77" />

< Player ID =" 133" />

< Player ID =" 144" />

< Player ID =" 195" />

< Player ID =" 220" />

< Player ID =" 231" />

< Player ID =" 214" />

< Team ID =" 13"市= QUOT;城2"名称= QUOT;名称2" City =" City2"

< Player ID =" 91" />

< Player ID =" 190" />

< Player ID =" 77" />

< Player ID =" 133" />

< Player ID =" 144" />

< Player ID =" 195" />

< Player ID =" 220" />

< Player ID =" 231" />

< Player ID =" 214" />

< / Team>

< /团队>

<匹配ID =" 999" StatusType = QUOT; 6英寸IsChallengeEnabled =" false"

VenueID =" NBB" SchedDate = QUOT; 2006-07-30" SchedTime =" 13:00"

ElapsedTime =" 02:01"赢家= QUOT; H"出勤= QUOT;" Final =Y>

< ChairUmpires>

< ChairUmpire Num =" 1"名称= QUOT;" />

< ChairUmpire Num =" 2"名称= QUOT;" />

< / ChairUmpires>

<团队>

<团队ID =" 1"类型=" H" ChallengesMade = QUOT; 5英寸ChallengesWon =3>

< Player ID =" 162"教练= QUOT; N" />

< Player ID =" 92"教练= QUOT; N" />

< Player ID =" 127"教练= QUOT; N" />

< Player ID =" 183"教练= QUOT; N" />

< Player ID =" 58"教练= QUOT; Y" />

< Stats FSPts =" 77" FSPtsWon = QUOT; 53" SSPts = QUOT; 21" SSPtsWon =" 11"

FSAces =" 2" SSAces = QUOT; 2英寸DF = QUOT; 2英寸TeamBrkPts = QUOT; 16" TeamBrkPtsWon =" 6"

TotPtsWon =" 110" TeamDeucePts = QUOT; 6英寸TeamDeucePtsWon = QUOT 1 QUOT; GamesPlayed =" 35"

GamesWon =" 21" />

< / Team>

< / Match>

< / Scoreboard>


我如何循环通过特定节点,例如Scoreboard / Teams

并仅提取该特定节点的所有信息?一旦

完成,我希望能够移动到另一个节点,例如

" Match / Teams"并仅遍历该节点并获取所有信息。我不需要循环浏览文件中的每个节点,只需要特定的




正如我所提到的,这个只是文件的一个小样本,它比这更复杂,但如果我能够进入这个阶段,我可以想象

休息。所有这些信息都必须放入数据库。


如果有人有一个如何做到这一点的例子,我真的会赞赏它。我迫切需要立即完成这项工作。


谢谢,

史蒂夫

I am quite new to XML and posted a request for example code yesterday.
Unfortunately, I did not do a very good job in explaining what I was
looking for. Here is an example of a small piece of the file:

<Scoreboard>
<Events>
<Event ID="001212" Name="EventName1" />
<Event ID="001213" Name="EventName2" />
<Event ID="001214" Name="EventName3" />
<Event ID="001215" Name="EventName4" />
</Events>
<EventTypes>
<EventType ID="01" SingleGame="true" Name="EventName1" />
<EventType ID="02" SingleGame="true" Name="EventName2" />
<EventType ID="03" SingleGame="true" Name="EventName3" />
<EventType ID="04" SingleGame="true" Name="EventName4" />
<EventType ID="05" SingleGame="true" Name="EventName5" />
<EventType ID="06" SingleGame="true" Name="EventName6" />
<EventType ID="07" SingleGame="true" Name="EventName7" />
</EventTypes>
<Teams>
<Team ID="11" City="City1" Name="Name1" City="City1"
Nickname="nickname1" Conference="Conference1">
<Player ID="91" />
<Player ID="190" />
<Player ID="77" />
<Player ID="133" />
<Player ID="144" />
<Player ID="195" />
<Player ID="220" />
<Player ID="231" />
<Player ID="214" />
<Team ID="13" City="City2" Name="Name2" City="City2"
Nickname="nickname2" Conference="Conference1">
<Player ID="91" />
<Player ID="190" />
<Player ID="77" />
<Player ID="133" />
<Player ID="144" />
<Player ID="195" />
<Player ID="220" />
<Player ID="231" />
<Player ID="214" />
</Team>
</Teams>
<Match ID="999" StatusType="6" IsChallengeEnabled="false"
VenueID="NBB" SchedDate="2006-07-30" SchedTime="13:00"
ElapsedTime="02:01" Winner="H" Attendance="" Final="Y">
<ChairUmpires>
<ChairUmpire Num="1" Name="" />
<ChairUmpire Num="2" Name="" />
</ChairUmpires>
<Teams>
<Team ID="1" Type="H" ChallengesMade="5" ChallengesWon="3">
<Player ID="162" Coach="N" />
<Player ID="92" Coach="N" />
<Player ID="127" Coach="N" />
<Player ID="183" Coach="N" />
<Player ID="58" Coach="Y" />
<Stats FSPts="77" FSPtsWon="53" SSPts="21" SSPtsWon="11"
FSAces="2" SSAces="2" DF="2" TeamBrkPts="16" TeamBrkPtsWon="6"
TotPtsWon="110" TeamDeucePts="6" TeamDeucePtsWon="1" GamesPlayed="35"
GamesWon="21" />
</Team>
</Match>
</Scoreboard>

How could I loop through a specific node, such as "Scoreboard/Teams"
and pull out all the information for ONLY that specific node? Once
that is done I would like to be able to move to another node such as
"Match/Teams" and loop through only that node and get all the info. I
would not need to loop through every node in the file, just specific
ones.

As I mentioned, this is just a small sample of the file, it is more
complex than this, but if I could get to this stage I could figure the
rest out. All this info must be put into a database.

Please if anyone has an example on how to do this, I would really
appreciate it. I am in urgent need of getting this done immediately.

Thanks,
Steve

推荐答案

6月3日下午5:58,gator< glb ... @ gmail.comwrote:
On Jun 3, 5:58 pm, gator <glb...@gmail.comwrote:

我很新到昨天发布了一个XML示例代码请求。

不幸的是,我没有很好地解释我在寻找什么是
。以下是该文件的一小部分示例:


<记分板>

<事件>

<事件ID =001212名称= QUOT; EventName1" />

<事件ID =" 001213"名称= QUOT; EventName2" />

<事件ID =" 001214"名称= QUOT; EventName3" />

<事件ID =" 001215"名称= QUOT; EventName4" />

< / Events>

< EventTypes>

< EventType ID =" 01" SingleGame = QUOT;真"名称= QUOT; EventName1" />

< EventType ID =" 02" SingleGame = QUOT;真"名称= QUOT; EventName2" />

< EventType ID =" 03" SingleGame = QUOT;真"名称= QUOT; EventName3" />

< EventType ID =" 04" SingleGame = QUOT;真"名称= QUOT; EventName4" />

< EventType ID =" 05" SingleGame = QUOT;真"名称= QUOT; EventName5" />

< EventType ID =" 06" SingleGame = QUOT;真"名称= QUOT; EventName6" />

< EventType ID =" 07" SingleGame = QUOT;真"名称= QUOT; EventName7" />

< / EventTypes>

<团队>

<团队ID =" 11"市= QUOT; City1"名称= QUOT;名1" City =" City1"

Nickname =" nickname1" Conference =" Conference1"

< Player ID =" 91" />

< Player ID =" 190" />

< Player ID =" 77" />

< Player ID =" 133" />

< Player ID =" 144" />

< Player ID =" 195" />

< Player ID =" 220" />

< Player ID =" 231" />

< Player ID =" 214" />

< Team ID =" 13"市= QUOT;城2"名称= QUOT;名称2" City =" City2"

< Player ID =" 91" />

< Player ID =" 190" />

< Player ID =" 77" />

< Player ID =" 133" />

< Player ID =" 144" />

< Player ID =" 195" />

< Player ID =" 220" />

< Player ID =" 231" />

< Player ID =" 214" />

< / Team>

< /团队>

<匹配ID =" 999" StatusType = QUOT; 6英寸IsChallengeEnabled =" false"

VenueID =" NBB" SchedDate = QUOT; 2006-07-30" SchedTime =" 13:00"

ElapsedTime =" 02:01"赢家= QUOT; H"出勤= QUOT;" Final =Y>

< ChairUmpires>

< ChairUmpire Num =" 1"名称= QUOT;" />

< ChairUmpire Num =" 2"名称= QUOT;" />

< / ChairUmpires>

<团队>

<团队ID =" 1"类型=" H" ChallengesMade = QUOT; 5英寸ChallengesWon =3>

< Player ID =" 162"教练= QUOT; N" />

< Player ID =" 92"教练= QUOT; N" />

< Player ID =" 127"教练= QUOT; N" />

< Player ID =" 183"教练= QUOT; N" />

< Player ID =" 58"教练= QUOT; Y" />

< Stats FSPts =" 77" FSPtsWon = QUOT; 53" SSPts = QUOT; 21" SSPtsWon =" 11"

FSAces =" 2" SSAces = QUOT; 2英寸DF = QUOT; 2英寸TeamBrkPts = QUOT; 16" TeamBrkPtsWon =" 6"

TotPtsWon =" 110" TeamDeucePts = QUOT; 6英寸TeamDeucePtsWon = QUOT 1 QUOT; GamesPlayed =" 35"

GamesWon =" 21" />

< / Team>

< / Match>

< / Scoreboard>


我如何循环通过特定节点,例如Scoreboard / Teams

并仅提取该特定节点的所有信息?一旦

完成,我希望能够移动到另一个节点,例如

" Match / Teams"并仅遍历该节点并获取所有信息。我不需要循环浏览文件中的每个节点,只需要特定的




正如我所提到的,这个只是文件的一个小样本,它比这更复杂,但如果我能够进入这个阶段,我可以想象

休息。所有这些信息都必须放入数据库。


如果有人有一个如何做到这一点的例子,我真的会赞赏它。我迫切需要立即完成这项工作。


谢谢,

Steve
I am quite new to XML and posted a request for example code yesterday.
Unfortunately, I did not do a very good job in explaining what I was
looking for. Here is an example of a small piece of the file:

<Scoreboard>
<Events>
<Event ID="001212" Name="EventName1" />
<Event ID="001213" Name="EventName2" />
<Event ID="001214" Name="EventName3" />
<Event ID="001215" Name="EventName4" />
</Events>
<EventTypes>
<EventType ID="01" SingleGame="true" Name="EventName1" />
<EventType ID="02" SingleGame="true" Name="EventName2" />
<EventType ID="03" SingleGame="true" Name="EventName3" />
<EventType ID="04" SingleGame="true" Name="EventName4" />
<EventType ID="05" SingleGame="true" Name="EventName5" />
<EventType ID="06" SingleGame="true" Name="EventName6" />
<EventType ID="07" SingleGame="true" Name="EventName7" />
</EventTypes>
<Teams>
<Team ID="11" City="City1" Name="Name1" City="City1"
Nickname="nickname1" Conference="Conference1">
<Player ID="91" />
<Player ID="190" />
<Player ID="77" />
<Player ID="133" />
<Player ID="144" />
<Player ID="195" />
<Player ID="220" />
<Player ID="231" />
<Player ID="214" />
<Team ID="13" City="City2" Name="Name2" City="City2"
Nickname="nickname2" Conference="Conference1">
<Player ID="91" />
<Player ID="190" />
<Player ID="77" />
<Player ID="133" />
<Player ID="144" />
<Player ID="195" />
<Player ID="220" />
<Player ID="231" />
<Player ID="214" />
</Team>
</Teams>
<Match ID="999" StatusType="6" IsChallengeEnabled="false"
VenueID="NBB" SchedDate="2006-07-30" SchedTime="13:00"
ElapsedTime="02:01" Winner="H" Attendance="" Final="Y">
<ChairUmpires>
<ChairUmpire Num="1" Name="" />
<ChairUmpire Num="2" Name="" />
</ChairUmpires>
<Teams>
<Team ID="1" Type="H" ChallengesMade="5" ChallengesWon="3">
<Player ID="162" Coach="N" />
<Player ID="92" Coach="N" />
<Player ID="127" Coach="N" />
<Player ID="183" Coach="N" />
<Player ID="58" Coach="Y" />
<Stats FSPts="77" FSPtsWon="53" SSPts="21" SSPtsWon="11"
FSAces="2" SSAces="2" DF="2" TeamBrkPts="16" TeamBrkPtsWon="6"
TotPtsWon="110" TeamDeucePts="6" TeamDeucePtsWon="1" GamesPlayed="35"
GamesWon="21" />
</Team>
</Match>
</Scoreboard>

How could I loop through a specific node, such as "Scoreboard/Teams"
and pull out all the information for ONLY that specific node? Once
that is done I would like to be able to move to another node such as
"Match/Teams" and loop through only that node and get all the info. I
would not need to loop through every node in the file, just specific
ones.

As I mentioned, this is just a small sample of the file, it is more
complex than this, but if I could get to this stage I could figure the
rest out. All this info must be put into a database.

Please if anyone has an example on how to do this, I would really
appreciate it. I am in urgent need of getting this done immediately.

Thanks,
Steve



史蒂夫,


尝试使用XPathNavigator类。
http://msdn2.microsoft.com/en-us/lib...navigator.aspx


希望这会有所帮助。

Moty

Hi Steve,

Try using XPathNavigator class.
http://msdn2.microsoft.com/en-us/lib...navigator.aspx

Hope this helps.
Moty




On Sun,2007年6月3日07 :58:06 -0700,gator< gl **** @ gmail.comwrote:

On Sun, 03 Jun 2007 07:58:06 -0700, gator <gl****@gmail.comwrote:

我是XML的新手,昨天发布了一个示例代码请求。

不幸的是,我没有很好地解释我在寻找什么是
。以下是该文件的一小部分示例:
I am quite new to XML and posted a request for example code yesterday.
Unfortunately, I did not do a very good job in explaining what I was
looking for. Here is an example of a small piece of the file:



.. [...]

.. [...]


>

我如何循环通过特定节点,例如记分板/团队
并仅提取该特定节点的所有信息?一旦

完成,我希望能够移动到另一个节点,例如

" Match / Teams"并仅遍历该节点并获取所有信息。我不需要循环遍历文件中的每个节点,只需具体的


>
How could I loop through a specific node, such as "Scoreboard/Teams"
and pull out all the information for ONLY that specific node? Once
that is done I would like to be able to move to another node such as
"Match/Teams" and loop through only that node and get all the info. I
would not need to loop through every node in the file, just specific
ones.



无需启动新线程,甚至不需要重新发布样本

数据。如果你觉得你应该详细说明或澄清原帖,

你可以而且应该简单地回复原来的帖子,这样所有相关的帖子都会保持在一起。


希望Moty'的回复解决你的问题。如果没有,那么你应该更加具体地了解这里的确切方式。您是否实际上在阅读数据时遇到了麻烦,因为您最近的帖子

建议?或者还有其他关于你想要实现的目标的事情是什么?b $ b麻烦实施?如果是这样,你究竟在尝试什么?

没有成功?


Pete

There is no need to start a new thread, or even to repost the sample
data. If you feel that you should elaborate or clarify the original post,
you can and should simply reply in that original thread, so that all of
the related posts stay together.

Hopefully Moty''s reply addresses your question. If not, then you should
probably be more specific about what exactly is in the way here. Are you
having trouble actually reading the data, as your most recent posts
suggests? Or is there something else about the desired goal you''re having
trouble implementing? If so, what exactly is it that you''re trying and
not having success with?

Pete


6月3日晚上9点35分,Peter Duniho < NpOeStPe ... @nnowslpianmk.com>

写道:
On Jun 3, 9:35 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:

On Sun,2007年6月3日07:58:06 -0700 ,gator< glb ... @ gmail.comwrote:
On Sun, 03 Jun 2007 07:58:06 -0700, gator <glb...@gmail.comwrote:

我对XML很新,昨天发布了一个示例代码请求。

不幸的是,我没有很好地解释我在寻找什么是
。以下是该文件的一小部分示例:
I am quite new to XML and posted a request for example code yesterday.
Unfortunately, I did not do a very good job in explaining what I was
looking for. Here is an example of a small piece of the file:



。 [...]


. [...]


我如何循环通过特定节点,例如记分板/团队

并将所有节点拉出来仅针对特定节点的信息?一旦

完成,我希望能够移动到另一个节点,例如

" Match / Teams"并仅遍历该节点并获取所有信息。我不需要循环遍历文件中的每个节点,只需具体的


How could I loop through a specific node, such as "Scoreboard/Teams"
and pull out all the information for ONLY that specific node? Once
that is done I would like to be able to move to another node such as
"Match/Teams" and loop through only that node and get all the info. I
would not need to loop through every node in the file, just specific
ones.



无需启动新线程,甚至不需要重新发布样本

数据。如果你觉得你应该详细说明或澄清原帖,

你可以而且应该简单地回复原来的帖子,这样所有相关的帖子都会保持在一起。


希望Moty'的回复解决你的问题。如果没有,那么你应该更加具体地了解这里的确切方式。您是否实际上在阅读数据时遇到了麻烦,因为您最近的帖子

建议?或者还有其他关于你想要实现的目标的事情是什么?b $ b麻烦实施?如果是这样,你究竟在尝试什么?

没有成功?


Pete


There is no need to start a new thread, or even to repost the sample
data. If you feel that you should elaborate or clarify the original post,
you can and should simply reply in that original thread, so that all of
the related posts stay together.

Hopefully Moty''s reply addresses your question. If not, then you should
probably be more specific about what exactly is in the way here. Are you
having trouble actually reading the data, as your most recent posts
suggests? Or is there something else about the desired goal you''re having
trouble implementing? If so, what exactly is it that you''re trying and
not having success with?

Pete



使用

XmlDataDocument xmlDoc = new XmlDataDocument();

xmlDoc.Load(" Sample.xml"); //或者使用xmlDoc.LoadXml(xmlData); // xmlData

是字符串

XmlNode myNode = xmlDoc.SelectSingleNode("" / mytable / myrow"); //根据你的xml架构修改

路径

现在你可以使用:

foreach(myNode.ChildNodes中的XmlNode fieldNode)

{

}


我猜Moly给了你正确的东西。这对你来说非常简单

。祝你好运!

Use
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load("Sample.xml"); //or use xmlDoc.LoadXml(xmlData);//xmlData
is string
XmlNode myNode =xmlDoc.SelectSingleNode(""/mytable/myrow");//modify
path according to ur xml schema
Now you can use:
foreach (XmlNode fieldNode in myNode.ChildNodes)
{
}

I guess Moly has given the right thing for you. This''d be pretty easy
for you. Good luck!


这篇关于请...通过特定节点循环的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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