小编And*_*ock的帖子

如何在C#中使用XML前缀?

编辑:我现在发布了我的应用程序: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);
        }


    }
}
Run Code Online (Sandbox Code Playgroud)

以下是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="&deg;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>
Run Code Online (Sandbox Code Playgroud)

我只是不确定如何在这里正确使用XML前缀.这有什么问题?

.net c# xml xmldocument

3
推荐指数
1
解决办法
1477
查看次数

标签 统计

.net ×1

c# ×1

xml ×1

xmldocument ×1