title: SelectSingleNode get attribute value
body: <p>I am trying to use the select single node to return a value from an XML that matches a particular xpath query.</p>
  <p>This is the code I am using,</p>
  <pre><code>XmlDocument doc = new XmlDocument();
  doc.Load(@&quot;C:\Program Files\Config.xml&quot;);
  
  string xPath;
  
  
  xPath = &quot;/Configuration/Service[@name='InfoRepositoryClient']/Environment/Parameter[@name='ORBPreferredInterfaces']&quot;;
  
  string value = doc.SelectSingleNode(xPath).Attributes[&quot;value&quot;].Value;
  
  Console.WriteLine(&quot;The value is {0}&quot;, value);
  
  Console.WriteLine(&quot;XML Doc is ...&quot;);
  </code></pre>
  <p>XML Sample,</p>
  <pre><code>&lt;Configuration version=&quot;7.2.0&quot; xmlns=&quot;event_collection/WinCollect&quot;&gt;
  &lt;Service version=&quot;7.2.0.799013&quot; classification=&quot;Service&quot; type=&quot;Service&quot; module=&quot;WinCollectCommon&quot; name=&quot;RegistryCache&quot;&gt;
      &lt;Environment/&gt;
  &lt;/Service&gt;
  &lt;Service version=&quot;7.2.0.799013&quot; classification=&quot;Static&quot; type=&quot;Service&quot; module=&quot;AgentCore&quot; name=&quot;AgentCore&quot;&gt;
      &lt;Environment&gt;
          &lt;Parameter value=&quot;300000&quot; name=&quot;HeartbeatInterval&quot;/&gt;
          &lt;Parameter value=&quot;60000&quot; name=&quot;ConfigurationCheckInterval&quot;/&gt;
          &lt;Parameter value=&quot;true&quot; name=&quot;Enabled&quot;/&gt;
          &lt;Parameter value=&quot;false&quot; name=&quot;Deleted&quot;/&gt;
      &lt;/Environment&gt;
  &lt;/Service&gt;
  &lt;Service version=&quot;7.2.0.799013&quot; classification=&quot;Service&quot; type=&quot;Service&quot; module=&quot;WinCollectCommon&quot; name=&quot;InfoRepositoryClient&quot;&gt;
      &lt;Environment&gt;
          &lt;Parameter value=&quot;0&quot; name=&quot;DCPSDebugLevel&quot;/&gt;
          &lt;Parameter value=&quot;*=127.0.0*&quot; name=&quot;ORBPreferredInterfaces&quot;/&gt;
          &lt;Parameter value=&quot;44380&quot; name=&quot;DomainId&quot;/&gt;
          &lt;Parameter value=&quot;corbaloc::127.0.0.1:12345/DCPSInfoRepo&quot; name=&quot;DCPSInfoRepo&quot;/&gt;
          &lt;Parameter value=&quot;1&quot; name=&quot;DCPSBit&quot;/&gt;
      &lt;/Environment&gt;
  &lt;/Service&gt;
  </code></pre>
  <p>When I run this I get Object reference not set to an instance of an object. When I debug I see that my value is getting set to null.</p>
  <p>I just want a quick query to pull out a value from an XML using XPath</p>
  <p>Note when I run xpath query in notepad ++ I get the following results</p>
  <blockquote>
  <p><code>1 hit</code></p>
  <p><code>Parameter </code></p>
  <p><code> - @Value: *=127.0.0*</code></p>
  <p><code> - @name: ORBPreferredInterfaces</code></p>
  </blockquote>