473,586 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c om/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.c om/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.c om/ns/ns12096.html</link>
<description>Th e 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.c om/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(n ew
StringReader(xm ldata));

xml_read.Whites paceHandling = WhitespaceHandl ing.None;

//Get all Items into node list...
XmlNodeList items = oXML.GetElement sByTagName("ite m");

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 1592
Ivan,

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

XmlNode pobjTitleNode = node.SelectSing leNode("title") ;
XmlNode pobjLinkNode = node.SelectSing leNode("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.co m

"Ivan Demkovitch" <i@a.b> wrote in message
news:ev******** ******@TK2MSFTN GP11.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.c om/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.c om/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.c om/ns/ns12096.html</link>
<description>Th e 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.c om/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(n ew
StringReader(xm ldata));

xml_read.Whites paceHandling = WhitespaceHandl ing.None;

//Get all Items into node list...
XmlNodeList items = oXML.GetElement sByTagName("ite m");

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.SelectSing leNode("title") .InnerText

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

For each node in the foreach statement ("node"), you can call the
SelectSingleNod e method and pass the name of the decendant element, like so:
XmlNode pobjTitleNode = node.SelectSing leNode("title") ;
XmlNode pobjLinkNode = node.SelectSing leNode("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.co m

"Ivan Demkovitch" <i@a.b> wrote in message
news:ev******** ******@TK2MSFTN GP11.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.c om/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.c om/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.c om/ns/ns12096.html</link>
<description>Th e 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.c om/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(n ew
StringReader(xm ldata));

xml_read.Whites paceHandling = WhitespaceHandl ing.None;

//Get all Items into node list...
XmlNodeList items = oXML.GetElement sByTagName("ite m");

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
1885
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, 7, 8, 9, bar, foo_6, foo_7, foo_8, foo_9, foo_10, foo_11 I need to read user input of a subset of these. The user will type a set of names...
16
2875
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 loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after...
6
3767
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 trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple...
2
1259
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 example below both <data> and <moredata> contains other nodes? I have been using both the XPathNavigator and the XMLNodeReader without finding a...
4
303
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 I need is a simple routine to parse this and display Name/Value pairs in a MSGBOX like: C1:myC1 C2:myC2
50
3970
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
1656
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 are exactly the same, but the execution result seems they are not equal. It works with firefox, but not with IE.
6
2676
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 learn/try a full blown parsing module. My simple script works well until it runs into functions that straddle multiple lines. For example: Call...
9
2244
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. (i.e. "Addhandler application/x-httpd-php .html .php" in .htaccess). He says it is a security problem. Is it possible to make a PHP counter...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7954
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.