簡體   English   中英

使用Lambda在Linq中獲取xml屬性值

[英]Getting xml Attribute value in Linq with Lambda

Let us consider the following xml Structure as

  <membership defaultProvider="SQLMembershipProvider">
      <providers>
        <add name="SQLMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="SQLMembershipConnString" applicationName=".NET Pet Shop 4.0" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" />
      </providers>
    </membership>

i have checked with the following code whether type contains "System.Web.Security.SqlMembershipProvider" follows as

 var prop1 = prop.Descendants(ns + "add").First(p => p.Attribute("type").Value == "System.Web.Security.SqlMembershipProvider");

my query is to get the attribute value of connectionStringName with the above query

waiting for your responses

你可以試試這個

var prop1 = xmldoc.Descendants("add").First(p => p.Attribute("type").Value == "System.Web.Security.SqlMembershipProvider").Attribute("connectionStringName").Value;  

希望這個能對您有所幫助...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM