Please ... example code due on looping though specific nodes

G

gator

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
 
M

Moty Michaely

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

Hi Steve,

Try using XPathNavigator class.
http://msdn2.microsoft.com/en-us/library/system.xml.xpath.xpathnavigator.aspx

Hope this helps.
Moty
 
P

Peter Duniho

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:
.. [...]

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.

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
 
A

Aneesh P

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:

. [...]
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.

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

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!
 
M

Mr. Arnold

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.

You mean to sit there and say that you cannot go out to Google and find
examples on how to do this and put two and two together?

You mean to say that you have to post to a NG and be crutched along, because
you're too lazy to go find an example of this yourself? :)
 
P

Peter Duniho

[abusive reply snipped] :)

Honestly. How does putting a smiley at the end of that post make it okay?

Most of the questions that are answered here could be addressed through
just reading the MSDN documentation, or experimenting with the API. I
don't think that justifies writing hostile replies such as yours when
someone posts such a question.

I have to admit, I have a hard time understanding the question, because it
looks like a pretty straightforward task to me. But I accept that not
everyone can "see" the solution right away, nor do I always "see" the
solution right away. It's a matter of perspective and sometimes what
seems like a dumb question really just needs someone to figure out what's
wrong with the poster's perspective and help them work their way to a
different point of view.

Regardless, I don't think that harassing someone just because they asked a
question is reasonable.

Pete
 
M

Mr. Arnold

There you go again trying put your spin on what I was saying. You simply
need to mind your own business and stay out of mine.
 
M

Mark Rae

There you go again trying put your spin on what I was saying. You simply
need to mind your own business and stay out of mine.

Seems like good advice for everyone - <plonk>
 
G

gator

There you go again trying put your spin on what I was saying. You simply
need to mind your own business and stay out of mine.

What is wrong with you? If you don't like my question ... don't
answer it. You told that guy to mind his own business, why don't you
take your advice and stay out of mine.
 
G

gator

. [...]
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.
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?

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!- Hide quoted text -

- Show quoted text -

Thanks to all for the help ... it's really appreciated.

- Steve
 
M

Mr. Arnold

gator said:
What is wrong with you? If you don't like my question ... don't
answer it. You told that guy to mind his own business, why don't you
take your advice and stay out of mine.

You made a top post here. It's not like I sought you out down in some
thread. And it's apparent that you're lazy and need someone to hold your
hand, when you should simply go find it yourself. It's not that hard. :)
 
G

gator

<snipped>




You mean to sit there and say that you cannot go out to Google and find
examples on how to do this and put two and two together?

You mean to say that you have to post to a NG and be crutched along, because
you're too lazy to go find an example of this yourself? :)



Uh ... when you think about it, couldn't this be said to ANY person
who EVER posted a question on this or ANY other news group???? Do you
do this to every thread or am I the lucky one who you posted to???
Why are you even here ... go away and bother someone else.

- Steve
 
M

Mr. Arnold

Uh ... when you think about it, couldn't this be said to ANY person
who EVER posted a question on this or ANY other news group???? Do you
do this to every thread or am I the lucky one who you posted to???
Why are you even here ... go away and bother someone else.

No one is bothering you. I am just telling it like it is. If you want
examples of what you're trying to do, the wheel has already been invented.
But you have to take it upon yourself to go find it and not be lazy.
 
G

gator

No one is bothering you. I am just telling it like it is. If you want
examples of what you're trying to do, the wheel has already been invented.
But you have to take it upon yourself to go find it and not be lazy.

Thanks for the "advice", but I am done with you ... you may go away
now.

- Steve
 
M

Mr. Arnold

Thanks for the "advice", but I am done with you ... you may go away
now.

I am done with you too. I hope you get your project done. I am sure you
will, but you are
struggling that's a fact, show some kind of guts and go find a solution,
putting two and two together. :)
 
G

Guest

Mr. Arnold said:
There you go again trying put your spin on what I was saying. You simply
need to mind your own business and stay out of mine.

Why ?

Your behavior is or should be a problem for all participants in
this newsgroup.

You are free to not reply to questions where you think the poster
has not tried solving the problem himself/herself.

You are also free to tell the poster that he/she can find
answers to the question via Google (GIYF).

But name calling for posting a question that are clearly
on topic and as far as I can see no different from many
other questions is not nice.

And you will have to live with criticism from other
that feel embarrassed on behalf of the NG.

Arne
 
M

Mr. Arnold

Arne Vajhøj said:
Why ?

Your behavior is or should be a problem for all participants in
this newsgroup.

There is nothing you can do about it.
You are free to not reply to questions where you think the poster
has not tried solving the problem himself/herself.

I am going to give he or she a push if I feel the need.
You are also free to tell the poster that he/she can find
answers to the question via Google (GIYF).

I already know that.
But name calling for posting a question that are clearly
on topic and as far as I can see no different from many
other questions is not nice.

If I was doing some kind of name calling, you would know it. I don't think
you know what name calling means.
And you will have to live with criticism from other
that feel embarrassed on behalf of the NG.

Yeah know, I don't care what others think. It means nothing to me. I stay
out of other people's business, down in the threads. You make a top post,
then that's another story altogether.
 
J

Jon Skeet [C# MVP]

Yeah know, I don't care what others think. It means nothing to me.

<snip>

I think you'll find you *will* care if you have a question that *you*
want answering and no-one is willing to help because of the attitude
you've been displaying in this thread and others. I know that *I'd*
certainly rather spend time trying to help someone who has a history of
being polite than someone who is often rude and unwilling to
acknowledge mistakes. I don't have enough time to answer every
question, so I have to apply some criteria to work out which ones to
spend effort on. Politeness is one of those criteria. Maybe that's just
me, but I strongly suspect it isn't.
 
G

gator

<snip>

I think you'll find you *will* care if you have a question that *you*
want answering and no-one is willing to help because of the attitude
you've been displaying in this thread and others. I know that *I'd*
certainly rather spend time trying to help someone who has a history of
being polite than someone who is often rude and unwilling to
acknowledge mistakes. I don't have enough time to answer every
question, so I have to apply some criteria to work out which ones to
spend effort on. Politeness is one of those criteria. Maybe that's just
me, but I strongly suspect it isn't.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hey guys,

I've found part of the answer to my question (thanks to several on
this thread) but I am unsure of how to finish. Here is the code I
have now:


XmlDocument doc = new XmlDocument();
doc.Load(sXMLFile);

string s = "";

XmlNodeList list = doc.SelectNodes("Scoreboard/Events");

foreach (XmlNode node in list)
{
s += "Title: " + node["EventType"].Attributes["ID"].Value ;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This gives me the first instance of the attribute "ID", which is a
good start, but how do I loop through the whole node "EventType" and
retreive the whole list of attributes?

Thanks in advance,
- Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with large XML file 2

Top