【发布时间】:2015-01-24 12:13:59
【问题描述】:
目前我可以在 XML 文档中选择属性,因为它们是唯一可识别的,如下所示:
XmlDocument weatherData = new XmlDocument();
weatherData.Load(query);
XmlNode channel = weatherData.SelectSingleNode("rss").SelectSingleNode("channel");
XmlNamespaceManager man = new XmlNamespaceManager(weatherData.NameTable);
man.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
town = channel.SelectSingleNode("yweather:location", man).Attributes["city"].Value;
但是如何从同名节点(yweather:forecast)中选择“文本”属性?
<yweather:forecast day="Sat" text="Sunny" code="32"/>
<yweather:forecast day="Sun" text="Partly Cloudy" code="30"/>
<yweather:forecast day="Mon" text="AM Showers" code="39"/>
<yweather:forecast day="Tue" text="Cloudy" code="26"/>
<yweather:forecast day="Wed" text="Cloudy/Wind" code="24"/>
是否有一个条件语句可以用来只选择text 属性,其中day 属性等于“Mon”?
【问题讨论】:
-
"yweather:location[@day = 'mon']/@city"