感谢您阅读我的帖子。我试图从以下 xml 文件加载 FFTExe 的值,但它节点返回 null。
这是我用来读取 xml 的代码
const string CMD_FFT = "/Command/FFTExe";
string strFile = Application.Current.Resources["ApplicationSettingsFolder"].ToString() + "\\CommandList.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strFile);
XmlNode node = doc.SelectSingleNode(CMD_FFT);
if (null != node) //<-----problem occurs here, node is null!!!
GetAttribute(node, doc, "value", ref FFTExeFile);
这是我的 xml 文件,我想从条目 FFTExe 的值中提取“D:\fft\fft.exe”
<?xml version="1.0" ?>
<CommandList>
<Command name="Capture" guid="30db4357-7508-46c9-84eb-3ca0900aa4c5" panel=".\Modules\ExperimentSettingsViewer.dll" description="">
<Experiment value="" />
<OutputPath value="" />
</Command>
<Command name="Run ImageJ Macro" guid="C1391459-132F-45ea-AE72-D7BEB2BD8086" panel=".\Modules\Panel.dll" description="">
<Macro value="" />
<DataFolder value="D:\out\" />
<FFTExe value="D:\fft\fft.exe" />
<Headless value="1" />
</Command>
</CommandList>
感谢您的任何建议。
我也尝试过
const string CMD_FFT = "/Command/Command/FFTExe";
和
const string CMD_FFT = "FFTExe";
运气不好
最佳答案
将 XPath 更改为 /CommandList/Command/FFTExe
,因为开头的单斜杠意味着从根开始,因此您需要包含 CommandList
根元素。
有关 XPath 的其他信息,请参阅此 link 。
关于c# - SelectSingleNode() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23295867/