从XML中选择特定节点值

时间:2013-02-14 04:44:06

标签: c# xml xmldocument

我有以下XML文档:

  <?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>

现在我必须从connectionstring节点中提取整个路径。我尝试使用以下代码:

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

但它似乎不起作用。知道如何让它发挥作用吗?

1 个答案:

答案 0 :(得分:3)

TRY

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

string nodeval=node.InnerText;