473,408 Members | 1,866 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,408 software developers and data experts.

Why do I allways get the same values?

Hello,

I am reading the <item> nodes from a XML file and add them to a dataset.

When I display my dataset in a datagrid I always see the same record.
It's like the For loop is not moving from one item to the next one.

This is my code:

' Load RSS File
Dim news As New XmlDocument()
news.Load("http://www.domain.com/_rss/news.rss")

' Create Dataset
Dim dsNews As DataSet = New DataSet()
dsNews.Tables.Add
dsNews.Tables(0).Columns.Add("title", GetType(String))
dsNews.Tables(0).Columns.Add("description", GetType(String))

' Read Item Nodes
Dim items As XmlNodeList =
news.SelectNodes("/rss[@version='2.0']/channel/item")

For Each item As XmlNode In items

Dim row As DataRow = dsNews.Tables(0).NewRow()
row.Item("title") =
CType(news.SelectSingleNode("/rss[@version='2.0']/channel/item/title").InnerText,
String)
row.Item("description") =
CType(news.SelectSingleNode("/rss[@version='2.0']/channel/item/description").InnerText,
String)
dsNews.Tables(0).Rows.Add(row)

Next

Can someone tell me what is wrong?

Thank You,
Miguel

Nov 19 '05 #1
1 947
Shapper wrote:
Hello,

I am reading the <item> nodes from a XML file and add them to a dataset.

When I display my dataset in a datagrid I always see the same record.
It's like the For loop is not moving from one item to the next one.

This is my code:

' Load RSS File
Dim news As New XmlDocument()
news.Load("http://www.domain.com/_rss/news.rss")

' Create Dataset
Dim dsNews As DataSet = New DataSet()
dsNews.Tables.Add
dsNews.Tables(0).Columns.Add("title", GetType(String))
dsNews.Tables(0).Columns.Add("description", GetType(String))

' Read Item Nodes
Dim items As XmlNodeList =
news.SelectNodes("/rss[@version='2.0']/channel/item")

For Each item As XmlNode In items

Dim row As DataRow = dsNews.Tables(0).NewRow()
row.Item("title") =
CType(news.SelectSingleNode("/rss[@version='2.0']/channel/item/title").InnerText,
String)
row.Item("description") =
CType(news.SelectSingleNode("/rss[@version='2.0']/channel/item/description").InnerText,
String)
dsNews.Tables(0).Rows.Add(row)

Next

Can someone tell me what is wrong?

Thank You,
Miguel


It's because you're doing the xpath query again inside of the for...each
loop. Once you have are looking at one of the item nodes inside the
loop, just look at its children (or do an xpath query from item, not
from news). something like:

item.SelectSingleNode("/description").InnerText

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2

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

Similar topics

4
by: Steve Hall | last post by:
Folks, My secnario involves two tables - ObservationRegister, and Person. ObservationRegister contains most of the "useful" fields, including the UserID of the person that raised the record, and...
0
by: BadMotherfucker | last post by:
Hello, I want to place some threads in an arraylist. (process is always the same) But no mather what I do, my tasks take allways the last thread, never one of the first created threads. I don't...
6
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like...
2
by: Hennie | last post by:
I apologise if this is a stupid question, but I would appreciated any help on this subject. I want to create a view (VIEW_1 in example below) where I take numeric values from a field in one...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
2
by: Rolf Welskes | last post by:
Hello, When developing Customcontrols which have other controls it seems be good practice to inherent from CompositeControl. But other as at WebControl I am not able to set the tag of the...
2
by: Goofy | last post by:
Even if the layout options are set to Absolute Positioning, the controls will allways go to the top elft which results in two actions to position a control on a page. Does anyone know how I can...
13
by: Gregor =?UTF-8?B?S292YcSN?= | last post by:
Hi! With VALUES you can do something like: SELECT * FROM (VALUES ('A', 1), ('B', 2), ('C', 2)) AS TEMP(LETTER, NUMBER) which will give you: LETTER NUMBER ------ ------ A 1 B 2...
12
by: Mads Aggerholm | last post by:
Hello Sirs I hope you can give me a hint to this little problem. The thing is, I have for a lang time enjoyed the comics on www.washintonpost.com, and I allways start the day by going to their...
8
by: gigonomics | last post by:
Hi all, I hope someone can help me out. I need to return the best available seats subject to the constraint that the seats are side by side (or return X consecutive records from a table column...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.