tags:

views:

59

answers:

3

Hi guys, this is an example of the XML I want to scrape:

http://www.dreamincode.net/forums/xml.php?showuser=335389

Notice that the contactinformation tag has many contact elements, each similar but with different values.

For example, the element that has the AIM content in it, how can I get the content of the Value tag that's in the same family as the AIM content element?

That's where I'm stuck. Thanks!

Basically: I need to find the AIM content tag, make a note of where it is, and find the Value element within that same family. Hope this makes the question clearer

+1  A: 

Have you tried to parse the XML rather than "scraping" it?

mmattax
I meant 'parse'.
Serg
+4  A: 

Using an xpath like the one below will get you the contact/value node where contact/title is "AIM":

/ipb/profile/contactinformation/contact[title='AIM']/value
Abe Miessler
Nevermind, it works. Thanks a bunch!
Serg
+4  A: 

LINQToXML

var doc = XDocument.Load(@"http://www.dreamincode.net/forums/xml.php?showuser=335389");
var aimElements = doc.Descendants("contact").Where(a=>a.Element("title").Value == "AIM").Select(a=>a.Element("value").Value);

this will give you a list of strings that hold the value of the value element for a contact that has the title AIM, you can do a First() or a FirstOrDefault if you believe there should only be 1

Pharabus
Great! I love the technology convergence (LINQ instead of XPath).
Yar