title: XPath in SelectNodes to choose all nodes where a particular grandchild node is present, regardless of value
body: <p>I have an XSD document, and I need to select all nodes that match a certain layout.</p>
  
  <p>Here's a snippet of the XSD:</p>
  
  <pre><code>&lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xsd:element name="MachineParameters"&gt;
      &lt;xsd:complexType&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="stMachineParameters"
           minOccurs="1"
           maxOccurs="1"&gt;
      &lt;xsd:complexType&gt;
        &lt;xsd:sequence&gt;
          &lt;xsd:element name="CPSPEED"
                       minOccurs="1"
               maxOccurs="1"&gt;
                    &lt;xsd:annotation&gt;
          &lt;xsd:documentation&gt;CPSPEEDDesc&lt;/xsd:documentation&gt;
          &lt;xsd:appinfo&gt;false&lt;/xsd:appinfo&gt;
            &lt;/xsd:annotation&gt;
            &lt;xsd:simpleType&gt;
                      &lt;xsd:restriction base = "xsd:decimal"&gt;
                      &lt;/xsd:restriction&gt;
                    &lt;/xsd:simpleType&gt;
                  &lt;/xsd:element&gt;  
                  &lt;xsd:element name="STVARZPARAMS"
                       minOccurs="1"
                               maxOccurs="1"&gt;
                    &lt;xsd:complexType&gt;
                      &lt;xsd:sequence&gt;
                        &lt;xsd:element name="VARIABLEZFASTVELOCITY"&gt;
                          &lt;xsd:annotation&gt;
                            &lt;xsd:documentation&gt;VARIABLEZFASTVELOCITYDesc&lt;/xsd:documentation&gt;
                            &lt;xsd:appinfo&gt;false&lt;/xsd:appinfo&gt;
                          &lt;/xsd:annotation&gt;
                          &lt;xsd:simpleType&gt;
                            &lt;xsd:restriction base = "xsd:decimal"&gt;
                              &lt;xsd:minInclusive value="0" /&gt;
                              &lt;xsd:maxInclusive value="1" /&gt;
                            &lt;/xsd:restriction&gt;
                          &lt;/xsd:simpleType&gt;
                        &lt;/xsd:element&gt;
  </code></pre>
  
  <p>And so on.</p>
  
  <p>I am trying to write some C# code to run through my entire document and return me a list of any element where an xsd:appinfo has been specified, regardless of value.</p>
  
  <p>I've been struggling with this for a while and feel like I am close, but so far I haven't hit on the right Xpath query (I haven't used it before).</p>
  
  <p>Here's the C#:</p>
  
  <pre><code>elementInfo = new Dictionary&lt;string, DictionaryInfo&gt;();
  
  XmlNodeList nodeList;
  XmlNode root = xmlDocSchema.DocumentElement;
  
  
  try
  {
      // the presence of an annotation/appinfo for the element is being used to identify it as a value element
      XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocSchema.NameTable);
      xmlNamespaceManager.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
      nodeList = root.SelectNodes("/*/element[/annotation/appinfo='false' or /annotation/appinfo='true']", xmlNamespaceManager);
  }
  catch (System.Xml.XPath.XPathException ex)
  {
      MessageBox.Show(string.Format("Xpath exception: {0}", ex.Message));
      nodeList = null;
  }
  catch (Exception ex)
  {
      MessageBox.Show(string.Format("General exception: {0}", ex.Message));
      nodeList = null;
  }
  </code></pre>
  
  <p>Could someone suggest where I'm going wrong (and how to go right!)?</p>