2012-10-16 1 views
0

제목이 뭔가와 같으면 RSS 피드에서 "설명"을 선택하려고합니다. 코드에서제목이 무언가와 같을 경우 RSS 피드에서 "설명"을 선택하려고합니다.

나는이 있습니다

public static XmlDocument GetDefaultHoroscopesFeed(string StarSign){ 
xdoc.SelectSingleNode(string.Format("rss/channel/item/[title = '{0}']/description", StarSign)); 
      xdoc.LoadXml(DefaultPageHoroscopeNode.InnerXml); 
      return xdoc; 

} 

을하지만 난이 오류가 점점 계속 : 표현은 노드 집합으로 평가해야합니다.

사람

답변

0

당신은 그러므로 유효한 노드 집합을 다시 얻을 수 없습니다, .../item/[title = ... 해당 증속 노드 이름을 지정하지 않을 도와주세요. 또한 RSS에서 <title> 노드에는 <description>이라는 하위 노드가 없습니다.

당신이이 <description> 노드를 검색 한 후 당신에게 값 StarSign와 <title> 노드가있는 <item> 노드를 얻을 것이다

"rss/channel/item[title = '{0}']/description" 

으로 XPath를

"rss/channel/item/[title = '{0}']/description" 

을 변경해야합니다.

는 또한과 같이, XML에 XDocument와 Linq에를 사용하여이 작업을 수행 할 수 있습니다 :

XDocument xdoc = XDocument.Load(pathToRss); 
XElement description = xdoc.Descendants("item") 
    .Where(i => i.Element("title").Value.Equals(StarSign)) 
    .Select(i => i.Element("description")) 
    .FirstOrDefault(); 
관련 문제