如何从 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);
关于c# - 当我知道确切的路径时,如何使用 c# 查找 XML 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11893511/