2017-02-24 51 views
0

只有當<IsDisabled>等於0時,C#中有沒有可能獲得<PropertyID>節點的值?C#當另一個是特定值時獲取一個XML元素值

如果不是,我將如何解析出IsDisabled值爲0的PropertyID?

我一直在這一整天都在毆打自己,所以任何幫助將不勝感激。

我附上了我的XML的一個示例代碼片段。我有顯著凝結,並有許多爲1的值,許多以0

<response> 
    <code>200</code> 
    <result> 
    <PhysicalProperty> 
     <Property> 
     <PropertyID>325213</PropertyID> 
     <MarketingName>XXXXX</MarketingName> 
     <Type>Student</Type> 
     <IsDisabled>1</IsDisabled> 
     <IsFeaturedProperty>0</IsFeaturedProperty> 
     </Property> 
    </PhysicalProperty> 
    </result> 
</response> 

回答

1

是,LINQ使得它很容易做到這些類型的查詢對XML

var propertyIds = XDocument.Parse(myXmlString) 
          .Descendants("Property") 
          .Where(p => p.Element("IsDisabled").Value == "0") 
          .Select(p => p.Element("PropertyID").Value); 
+0

確定。我有種得到它。在這種情況下,你的代碼中的p是什麼意思? – Mitch

+0

'=>'表示一個匿名方法。左側('p')是進入方法的參數,右側是方法體。你可以研究'匿名方法'或'lambda' – Jonesopolis

相關問題