开发者

How can I select an XML element if there are three of the same elements there?

Given this XML found here.

How can I get each contact item individually?

For exam开发者_StackOverflow社区ple, 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?


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

If that doesn't work, try

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


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜