开发者

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

开发者 https://www.devze.com 2023-01-06 04:14 出处:网络
Given this XML found here. How can I get each contact item individually? For exam开发者_StackOverflow社区ple, say I wanted to get only twitter:

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

精彩评论

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