tags:

views:

40

answers:

2

Given this XML found here.

How can I get each contact item individually?

For example, say I wanted to get only twitter:

I tried this:

return doc.XPathSelectElement("/ipb/profile/contactinformation/contact[type/text() = 'LinkedIn']/value").Value;

But that returns nothing. Any help?

+2  A: 

/test/contactinfo/contact[type = 'Twitter']/address

If that doesn't work, try

/test/contactinfo/contact[type/text() = 'Twitter']/address

Gregory Higley
It's not working. :( Can you please see my edit?
Sergio Tapia
Given your new XML, the appropriate XPath is `//contact[title='Twitter']/value`.
Porges
Yes, thanks a bunch!
Sergio Tapia
Sergio, you could easily have figured this out yourself by analogy, although Porges was nice enough to do it for you.
Gregory Higley
A: 
var profile = doc.Root.Element("profile");

var contactinfo = profile.Element("contactinformation");

var contacts = from contact in contactinfo.Elements("contact")
               where (string)contact.Element("title") == "Twitter"
               select contact;

var result = (string)contacts.Single().Element("value");
dtb