我正在使用C#XmlDocument API。XmlDocument XPath表达式失败
我有下面的XML:
<Node1>
<Node2>
<Node3>
</Node3>
</Node2>
</Node1>
我想作为节点3一个XmlNode。但我的代码返回null:
XmlDocument doc = new XmlDocument();
doc.Load(reader);
XmlNode root_node = doc.DocumentElement.SelectSingleNode("/Node1");
Log(root_node.OuterXml);
XmlNode test_node = root_node.SelectSingleNode("/Node2/Node3");
if (test_node == null)
Logger.Log.Error(" --- TEST NODE IS NULL --- ");
的日志root_node.OuterXml
日志
<Node1><Node2><Node3>.....
但test_node
返回null。
这里怎么回事?
你想在这里完成什么? –
test_node的作用域为Node3,而不是null。 – ScottF