title: Check if XML node value already exists in xml file using c#
body: <p>Please note that I'm new to C# and I learn it right now :) I couldn't find something similar to my problem, so I came here.</p>
  
  <p>I have an application in which I add customers (it's in the final stage). All customers are stored in an XML file. Every single customer gets a new customer number. In my xml file I got an <code>XmlNode</code> called <code>CustNo</code>. Now if the user add a new customer and type in a number which already exist, it should pop up a message box to say that this number already exists. I got this c# code:</p>
  
  <pre><code>XDocument xdoc = XDocument.Load(path + "\\save.xml");
  var xmlNodeExist = String.Format("Buchhaltung/Customers/CustNo");
  var CustNoExist = xdoc.XPathSelectElement(xmlNodeExist);
  
  if (CustNoExist != null)
  {
     MessageBox.Show("asdf");
  }
  </code></pre>
  
  <p>And my XML file looks like this:</p>
  
  <pre><code>&lt;Buchhaltung&gt;
      &lt;Customers&gt;
          &lt;CustNo&gt;12&lt;/CustNo&gt;
          &lt;Surname&gt;Random&lt;/Surname&gt;
          &lt;Forename&gt;Name&lt;/Forename&gt;
          &lt;Addr&gt;Address&lt;/Addr&gt;
          &lt;Zip&gt;12345&lt;/Zip&gt;
          &lt;Place&gt;New York&lt;/Place&gt;
          &lt;Phone&gt;1234567890&lt;/Phone&gt;
          &lt;Mail&gt;example@test.com&lt;/Mail&gt;
      &lt;/Customers&gt;
      &lt;Customers&gt;
          &lt;CustNo&gt;13&lt;/CustNo&gt;
          &lt;Surname&gt;Other&lt;/Surname&gt;
          &lt;Forename&gt;Forename&lt;/Forename&gt;
          &lt;Addr&gt;My Address&lt;/Addr&gt;
          &lt;Zip&gt;67890&lt;/Zip&gt;
          &lt;Place&gt;Manhattan&lt;/Place&gt;
          &lt;Phone&gt;0987654321&lt;/Phone&gt;
          &lt;Mail&gt;test@example.com&lt;/Mail&gt;
      &lt;/Customers&gt;
  &lt;/Buchhaltung&gt;
  </code></pre>
  
  <p>But then the message box <strong>always</strong> pops up. What am I doing wrong?</p>