编辑:我现在已经发布了我的应用程序:http://pastebin.com/PYAxaTHU
我试图制作一个基于控制台的应用程序,返回我的温度。
using System;
using System.Xml;
namespace GetTemp
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(downloadWebPage(
"http://www.andrewmock.com/uploads/example.xml"
));
XmlNamespaceManager man = new XmlNamespaceManager(doc.NameTable);
man.AddNamespace("aws", "www.aws.com/aws");
XmlNode weather = doc.SelectSingleNode("aws:weather", man);
Console.WriteLine(weather.InnerText);
Console.ReadKey(false);
}
}
}
这是一个示例XML文件:
以下是示例代码:
<aws:weather xmlns:aws="http://www.aws.com/aws">
<aws:api version="2.0"/>
<aws:WebURL>http://weather.weatherbug.com/WA/Kenmore-weather.html?ZCode=Z5546&Units=0&stat=BOTHL</aws:WebURL>
<aws:InputLocationURL>http://weather.weatherbug.com/WA/Kenmore-weather.html?ZCode=Z5546&Units=0</aws:InputLocationURL>
<aws:station requestedID="BOTHL" id="BOTHL" name="Moorlands ES" city="Kenmore" state=" WA" zipcode="98028" country="USA" latitude="47.7383346557617" longitude="-122.230278015137"/>
<aws:current-condition icon="http://deskwx.weatherbug.com/images/Forecast/icons/cond024.gif">Mostly Cloudy</aws:current-condition>
<aws:temp units="°F">40.2</aws:temp>
<aws:rain-today units=""">0</aws:rain-today>
<aws:wind-speed units="mph">0</aws:wind-speed>
<aws:wind-direction>WNW</aws:wind-direction>
<aws:gust-speed units="mph">5</aws:gust-speed>
<aws:gust-direction>NW</aws:gust-direction>
</aws:weather>
我只是不确定如何正确使用 XML 前缀。这里有什么问题吗?