-1
我有下面的xml。如何读取XML节点值或名称c#
<Data>
<DateTime date="05-26-2016">
<Time time="09:53:46 AM">Test1</Time>
</DateTime>
<DateTime date="05-27-2016">
<Time time="09:54:56 AM">Test2</Time>
</DateTime>
</Data>
我使用下面的代码来获取DateTime的名称/值,但它是给null。
xmlDoc.Load(@"E:\testdoc.xml");
XmlElement rootNode = xmlDoc.DocumentElement;
foreach (XmlElement a in rootNode.ChildNodes)
{
var attributeValue = a.GetAttribute("Value");
if (a.Attributes["Value"].Value == attribute2.Value)
{
a.AppendChild(userChildNode2);
}
}
在foreach循环中,“attributeValue”所需的输出应该是“05-26-2016”/ 05-27-2016。有人能让我知道我在想什么吗?
。但不是输入我给了xml路径。它给我错误在根目录下的数据是无效的。第1行,第1位。 – Farhan
你的'xml'有问题,只是尝试用Internet Explorer或任何其他工具打开,你可以找出缺少的东西。 –
<?XML版本= “1.0” 编码= “UTF-8”?> <日期时间日期= “2016年5月26日”> <时间时间= “上午09点53分46秒”>测试1 <日期时间日期= “2016年5月27日”> <时间时间= “上午09点54分56秒”> Test2的 – Farhan