Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Apr 11, 2007 02:49 PM|LINK
I've searched for an answer to this, as I'm sure it will have been asked before, but can't find anything. It's quite a simple query..
I'm reading from a XML feed from a URL and can successfully loop through a node list for a top level node. However, within the Article node is a node called Categories, as an article can be associated with multiple categories. I then need to loop through
this node list within each Article. In VB, I can do this as below, but I need to convert this to C# and can't find the equivalent
Dim xtr As XmlTextReader = New XmlTextReader("http://feed.url.com")
xtr.WhitespaceHandling = WhitespaceHandling.None
Dim X As New XmlDocument
If Not X Is Nothing Then
Dim ArticleList As XmlNodeList = X.SelectNodes("InfoStreamResults/Article")
Dim Article As XmlNode
For Each Article In ArticleList
Dim CatNodesList As XmlNodeList = Article.SelectNodes("Categories/Category")
Dim category As XmlNode
For Each category In CatNodesList
' do stuff, i.e.
If Not Article.SelectSingleNode("nodename") Is Nothing Then
Catch ex As Exception
II can do the outer loop in C# fine, but when it comes to the equivalent of lines 17 to 28 as above, this DOESN'T work;
1 foreach (XmlNode category
3 categoryID = category.SelectSingleNode("@ID").Value;
4 categoryName = EncodeIt(category.SelectSingleNode("category").InnerText);
So how do I loop through a set of sub nodes within a node using foreach as I do in VB.NET, but in C#?
Thanks, hope that makes sense.