2013-02-14 51 views
1

特定節點的值,我有以下XML文檔:選擇從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;[email protected]</connectionstring> 
    </appSettings> 

現在我已經從connectionstring節點提取的完整路徑。我試着用下面的代碼:

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

但它似乎沒有工作。任何想法如何使其工作?

+0

你可以分享你的錯誤的屏幕截圖 – 2013-02-14 04:48:01

+0

我試過了。它沒有上傳。在調試它,我得到的是'System.XML.XMLelementlist' – Esha 2013-02-14 04:56:19

+1

請參閱此鏈接「http://stackoverflow.com/questions/6442024/getting-specified-node-values-from-xml-document」我希望這可能會對你有所幫助 – 2013-02-14 04:59:45

回答

3

TRY

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

string nodeval=node.InnerText; 
+0

謝謝!加工! – Esha 2013-02-14 05:09:58