2010-07-05 3 views
1

주어진 경우 XML found here.거기에 동일한 요소가 3 개있는 경우 XML 요소를 어떻게 선택할 수 있습니까?

개별적으로 각 연락처 항목을 가져올 수 있습니까?

나는이 시도 :

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

을하지만 아무것도 반환하지

예를 들어

, 나는 단지 트위터 얻고 싶었다 말한다. 어떤 도움이 필요합니까? 그래도 문제가 해결되지 않으면

답변

2

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

, 그것은 작동하지 않습니다

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

+0

보십시오. :(내 편집을 볼 수 있습니까? –

+1

새 XML이 주어지면, 적절한 XPath는'// contact [title = 'Twitter']/value'입니다. – porges

+0

그래, 고마워요 –

0
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"); 
관련 문제