Aqua-Soft Forums: C# & Xml Nodes - Help! - Aqua-Soft Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

C# & Xml Nodes - Help! Rate Topic: -----

#1 User is offline   djwilliams Icon

  • Group: Member
  • Posts: 277
  • Joined: 15-February 05

Posted 16 May 2009 - 08:55 PM

I have a problem. I want to retrieve all the title attributes from the [array key] node

You can view the XML here http://api.ustream.tv/xml/user/socaldavis/...7fescmekvx35f3q

The method I have below is only returning on value. When I know there are three! Can anyone help me with this? I am not all that good with XPath Syntext.


public string GetChannelList()
		{
			XmlDocument xdoc = new XmlDocument();
			xdoc.Load("http://api.ustream.tv/xml/user/socaldavis/listAllChannels?key=kdbkes7hh7fescmekvx35f3q");
			
			XmlElement root = xdoc.DocumentElement;
		   //I do this because using "array key=*" throws an invalid token error
			XmlNodeList nodes = root.SelectNodes("//xml//results//node()"); 
			
			foreach (XmlNode theNode in nodes)
			{
				string data = theNode["title"].InnerText;
				frmMain.lstResults.Items.Add(data);
				
				return data;
			}
			return null;
		}

0

#2 User is offline   matonga Icon

  • Group: Developers
  • Posts: 1,286
  • Joined: 04-September 06

Posted 16 May 2009 - 09:49 PM

I'm not sure, but... try commenting out return data; and see if then correctly fills lstResults with all three results.
0

#3 User is offline   Smaky Icon

  • Group: Member
  • Posts: 586
  • Joined: 19-April 08

Posted 17 May 2009 - 12:46 AM

Looking at the xml returned from the URL you mentioned, it seems to me that you should look for array elements by using an XPath expression like root.SelectNodes("//xml//results//array//node()");

Since results elements are only one, but there are three array elements.

Hope I read your question properly.
0

#4 User is offline   djwilliams Icon

  • Group: Member
  • Posts: 277
  • Joined: 15-February 05

Posted 17 May 2009 - 03:00 AM

You both helped me on this :) I commented out the return and I used "//xml//restuls//array" and now I get all the results. So simple. Thank a ton guys.
0

#5 User is offline   Smaky Icon

  • Group: Member
  • Posts: 586
  • Joined: 19-April 08

Posted 17 May 2009 - 11:27 PM

Don't mention it... I'm glad we could help you out.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic