SelectSingleNode()返回null

时间:2014-04-25 14:25:27

标签: c# xml

感谢您阅读我的帖子。我试图从跟随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文件,我要提取&#34; D:\ fft \ fft.exe&#34;从条目FFTExe的值

<?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"; 

没有运气

1 个答案:

答案 0 :(得分:2)

将XPath更改为/CommandList/Command/FFTExe作为开头的单斜杠意味着从根开始,因此您需要包含CommandList根元素。

有关XPath的其他信息,请参阅此link

相关问题