Search code examples
c#xmlxmldocument

Select particular node value from XML


I have the following XML Document:

  <?xml version="1.0" encoding="utf-8" ?> 
  <appSettings>
  <Path> blahblahblah </Path> 
  <PathValue> blahblahblah </PathValue> 
  <domainName> blahblahblah </domainName> 
  <SuperUserEmail> blahblahblah </SuperUserEmail> 
  <SuperUserName> blahblahblah </SuperUserName> 
  <UserName> blahblahblah </UserName> 
  <Password> blahblahblah </Password>       
  <connectionstring>Data Source=ABC\SQLEXPRESS;Initial Catalog=mail;User ID=sa;Password=sa@</connectionstring> 
  </appSettings>

Now I have to extract the entire path from connectionstring node. I tried using the following code:

XmlNodeList xnList = xml.SelectNodes("/appSettings/connectionstring");

but it doesn't seem to work. Any idea how to make it work?


Solution

  • TRY

    XmlNode node = xml.DocumentElement.SelectSingleNode("/appSettings/connectionstring");
    
    string nodeval=node.InnerText;