当我知道确切的路径时,如何使用c#查找XML元素?

当我知道确切的路径时,如何使用c#查找XML元素?,c#,xpath,xpathnavigator,C#,Xpath,Xpathnavigator,如何从xml文档中获取信息? 我在c:\temp\data.xml上有一个xml文档,正在使用visual studio 我能想到的最接近的数字是: XmlDocument xdoc = new XmlDocument(); xdoc.Load(@"C:\temp\data.xml"); date = xdoc.SelectSingleNode("/forcast_informat… XML文档如下所示: <?xml version="1.0"?> -<xml_api_rep

如何从xml文档中获取信息? 我在c:\temp\data.xml上有一个xml文档,正在使用visual studio

我能想到的最接近的数字是:

XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"C:\temp\data.xml");
date = xdoc.SelectSingleNode("/forcast_informat…
XML文档如下所示:

<?xml version="1.0"?>
-<xml_api_reply version="1">
    -<weather section="0" row="0" mobile_zipped="1" mobile_row="0" tab_id="0" module_id="0">
        -<forecast_information>
             etc etc...
             <current_date_time data="2012-08-09 21:53:00 +0000"/>
             etc, etc...

-
-
-
等等等等。。。
等等,等等。。。

我想做的就是抓住2012-08-09 21:53:00+0000的日期…有什么建议吗?

这应该可以做到:

XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"C:\temp\data.xml");
XmlNode dataAttribute = xdoc.SelectSingleNode("/xml_api_reply/weather/forecast_information/current_date_time/@data");

Console.WriteLine(dataAttribute.Value);

试试这个。这将为每个预测加载当前日期和时间:

XmlDocument XMLDoc = new XmlDocument();
XMLDoc.Load(XMLDocumentPath);
XmlNodeList NodeList = XMLDoc.SelectNodes("/xml_api_reply/weather/forecast_information/");
foreach(XmlNode Node in NodeList)
{
string DTime = Node["current_date_time"].InnerText;
//Do something with DTime
}