我将开始我的第一个XPathNavigator
实例。
这是我的简单xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<theroot>
<thisnode>
<thiselement visible="true" dosomething="false"/>
<another closed node />
</thisnode>
</theroot>
现在,我正在使用
CommonLibrary.NET
库来帮助我一些: public static XmlDocument theXML = XmlUtils.LoadXMLFromFile(PathToXMLFile);
const string thexpath = "/theroot/thisnode";
public static void test() {
XPathNavigator xpn = theXML.CreateNavigator();
xpn.Select(thexpath);
string thisstring = xpn.GetAttribute("visible","");
System.Windows.Forms.MessageBox.Show(thisstring);
}
问题是它找不到属性。我已经查看了MSDN的文档,但对所发生的事情无法理解。
XPathNavigator
中 - 我想我认为它的工作方式不同。我还发现了这个链接,它以简单的方式呈现了它:https://dev59.com/tG855IYBdhLWcg3wfUfQ?rq=1 - bgmCoderstring thisstring = xpn.GetAttribute("visible","");Console.WriteLine(thisstring);
的输出是什么?在这种情况下,输出应该为true
。 - JLRishe