473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Simple XML parsing question..

Hi!

I'm trying to parse RSS news feed with code as simple as possible.

Simple XML:
<?xml version="1.0"?>
<rss version="2.0">
<channel>

<item>
<title>The situation of F1 in Russia</title>
<link>http://www.grandprix.com/ns/ns12094.html</link>
<description>R-Fast, the Russian Federation of Autosport and Tourism, the
national sporting authority of Russia, has been giving details of its plans
to increase motor racing activities in Russia. These date back to 1998 when
R-FAST began working with the Moscow City Government on the idea of an
international racing circuit in the city. </description>
<guid>http://www.grandprix.com/ns/ns12094.html</guid>
<pubDate>Tue, 28 Oct 2003 8:36:40 GMT</pubDate>
</item>

<item>
<title>Massa at Sauber - it's official</title>
<link>http://www.grandprix.com/ns/ns12096.html</link>
<description>The long-awaited announcement from Sauber that Felipe Massa
will be driving of the team in 2004 is no surprise. Massa has agreed a
two-year deal with the Swiss team but it is expected that he will have a
get-out clause to move to Ferrari in 2005 if a drive is
available.</description>
<guid>http://www.grandprix.com/ns/ns12096.html</guid>
<pubDate>Tue, 28 Oct 2003 14:43:20 GMT</pubDate>
</item>

</channel>
</rss>

Now I'm writing code:

void XMLParse(string xmldata) {

//using Microsoft XML Parser
XmlTextReader xml_read = new XmlTextReader(new
StringReader(xmldata));

xml_read.WhitespaceHandling = WhitespaceHandling.None;

//Get all Items into node list...
XmlNodeList items = oXML.GetElementsByTagName("item");

foreach(XmlNode node in items){

//What's here???
}


QUESTION??

When in foreach I need simply get values of title, link, guid and pubDate

How do I do it?

Nov 15 '05 #1
2 1579
Ivan,

For each node in the foreach statement ("node"), you can call the
SelectSingleNode method and pass the name of the decendant element, like so:

XmlNode pobjTitleNode = node.SelectSingleNode("title");
XmlNode pobjLinkNode = node.SelectSingleNode("link");

And so on. From there, you can use the properties of the node to get
the text.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ivan Demkovitch" <i@a.b> wrote in message
news:ev**************@TK2MSFTNGP11.phx.gbl...
Hi!

I'm trying to parse RSS news feed with code as simple as possible.

Simple XML:
<?xml version="1.0"?>
<rss version="2.0">
<channel>

<item>
<title>The situation of F1 in Russia</title>
<link>http://www.grandprix.com/ns/ns12094.html</link>
<description>R-Fast, the Russian Federation of Autosport and Tourism, the
national sporting authority of Russia, has been giving details of its plans to increase motor racing activities in Russia. These date back to 1998 when R-FAST began working with the Moscow City Government on the idea of an
international racing circuit in the city. </description>
<guid>http://www.grandprix.com/ns/ns12094.html</guid>
<pubDate>Tue, 28 Oct 2003 8:36:40 GMT</pubDate>
</item>

<item>
<title>Massa at Sauber - it's official</title>
<link>http://www.grandprix.com/ns/ns12096.html</link>
<description>The long-awaited announcement from Sauber that Felipe Massa
will be driving of the team in 2004 is no surprise. Massa has agreed a
two-year deal with the Swiss team but it is expected that he will have a
get-out clause to move to Ferrari in 2005 if a drive is
available.</description>
<guid>http://www.grandprix.com/ns/ns12096.html</guid>
<pubDate>Tue, 28 Oct 2003 14:43:20 GMT</pubDate>
</item>

</channel>
</rss>

Now I'm writing code:

void XMLParse(string xmldata) {

//using Microsoft XML Parser
XmlTextReader xml_read = new XmlTextReader(new
StringReader(xmldata));

xml_read.WhitespaceHandling = WhitespaceHandling.None;

//Get all Items into node list...
XmlNodeList items = oXML.GetElementsByTagName("item");

foreach(XmlNode node in items){

//What's here???
}


QUESTION??

When in foreach I need simply get values of title, link, guid and pubDate

How do I do it?


Nov 15 '05 #2
Actually is was simpler (just got it)
Let me know if this could present problems:

node.SelectSingleNode("title").InnerText

returned what I needed saving some lines of code...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2***************@TK2MSFTNGP09.phx.gbl...
Ivan,

For each node in the foreach statement ("node"), you can call the
SelectSingleNode method and pass the name of the decendant element, like so:
XmlNode pobjTitleNode = node.SelectSingleNode("title");
XmlNode pobjLinkNode = node.SelectSingleNode("link");

And so on. From there, you can use the properties of the node to get
the text.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ivan Demkovitch" <i@a.b> wrote in message
news:ev**************@TK2MSFTNGP11.phx.gbl...
Hi!

I'm trying to parse RSS news feed with code as simple as possible.

Simple XML:
<?xml version="1.0"?>
<rss version="2.0">
<channel>

<item>
<title>The situation of F1 in Russia</title>
<link>http://www.grandprix.com/ns/ns12094.html</link>
<description>R-Fast, the Russian Federation of Autosport and Tourism, the national sporting authority of Russia, has been giving details of its

plans
to increase motor racing activities in Russia. These date back to 1998

when
R-FAST began working with the Moscow City Government on the idea of an
international racing circuit in the city. </description>
<guid>http://www.grandprix.com/ns/ns12094.html</guid>
<pubDate>Tue, 28 Oct 2003 8:36:40 GMT</pubDate>
</item>

<item>
<title>Massa at Sauber - it's official</title>
<link>http://www.grandprix.com/ns/ns12096.html</link>
<description>The long-awaited announcement from Sauber that Felipe Massa
will be driving of the team in 2004 is no surprise. Massa has agreed a
two-year deal with the Swiss team but it is expected that he will have a
get-out clause to move to Ferrari in 2005 if a drive is
available.</description>
<guid>http://www.grandprix.com/ns/ns12096.html</guid>
<pubDate>Tue, 28 Oct 2003 14:43:20 GMT</pubDate>
</item>

</channel>
</rss>

Now I'm writing code:

void XMLParse(string xmldata) {

//using Microsoft XML Parser
XmlTextReader xml_read = new XmlTextReader(new
StringReader(xmldata));

xml_read.WhitespaceHandling = WhitespaceHandling.None;

//Get all Items into node list...
XmlNodeList items = oXML.GetElementsByTagName("item");

foreach(XmlNode node in items){

//What's here???
}


QUESTION??

When in foreach I need simply get values of title, link, guid and pubDate
How do I do it?



Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: george young | last post by:
For each run of my app, I have a known set of (<100) wafer names. Names are sometimes simply integers, sometimes a short string, and sometimes a short string followed by an integer, e.g.: 5, 6,...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
2
by: Vegard Beider | last post by:
Hi. I am new to both C# and XML parsing. I simply want to find out if a node contains other nodes, and if it does i want to do something with it. How can i find out in a simple way that in the...
4
by: Wardeaux | last post by:
All, this XML is killing me... I'm new to XML, all I want to do is parse an XML string so that I can read the values... Mystr = "<A1><B1><C1>myC1</C1><C2>myC2</C2></B1><B2>myB2</B2><A1>" All...
50
by: Doug | last post by:
I can't imagine this is that hard but I'm sure having a struggle finding it. How do I convert a value like "111403" do a DateTime variable in DotNet (i.e. 11/14/2003)?
7
by: db | last post by:
Hi@all Just got a comparison problem with javascript. I want to compare : document.getElementById(currentID).getAttribute("style") with a string, e.g: "background-color: lightgreen;" They...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
9
by: Pygmalion | last post by:
I have found dozen of useful PHP counters on the web. However, nobody is working for my web pages, since administrator does not want to enable the possibility that PHP could be called from HTML. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.