tags:

views:

54

answers:

1

It has been years since I messed with XPath and need some guidance.

Here is the xml fragment:

<?xml version="1.0" encoding="utf-8"?>
<ConfigurationObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" i:type="AlgorithmDataSourceConfiguration" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://www.foo.com/bar/2008/03"&gt;
  <ConfigurationSection z:Id="2">
    <Type z:Id="3">
      <Name z:Id="4">AlgorithmDataSource</Name>

CODE:

        XmlDocument doc = new XmlDocument();
        doc.Load(path);
        XmlNamespaceManager mng = new XmlNamespaceManager(doc.NameTable);

        mng.AddNamespace("z", "http://schemas.microsoft.com/2003/10/Serialization/");

        XmlNodeList list = doc.SelectNodes("ConfigurationObject/ConfigurationSection /@z:Id=\"4\"",mng);
        foreach(XmlNode s in list)
        {
            Console.WriteLine(s.InnerText);
        }

The list doesn't contain any nodes??

What do you think?

A: 

From the xml fragment you provide, this xpath:

//ConfigurationObject/ConfigurationSection[@z:Id='2']

would select the first ConfigurationSection node.

santiiiii