Ono
Ono

Reputation: 1357

SelectSingleNode() returns null

Thanks for reading my thread. I am trying to load the value of FFTExe from following xml file, but it node returns null.

Here is the code I use to read the 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);

Here is my xml file, where I want to extract "D:\fft\fft.exe" from entry FFTExe's value

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

Thank you any suggestions.

I also tried

const string CMD_FFT = "/Command/Command/FFTExe"; 

and

const string CMD_FFT = "FFTExe"; 

no luck

Upvotes: 2

Views: 142

Answers (1)

Markus
Markus

Reputation: 22501

Change your XPath to /CommandList/Command/FFTExe as a single slash at the beginning means to start at the root so you need to include the CommandList root element.

For additional info on XPath see this link.

Upvotes: 2

Related Questions