<CardsClass cardclassID="10000" text="费用卡">
        
<item itemID="10001" text="月卡"></item>
        
<item itemID="10002" text="季卡"></item>
        
<item itemID="10003" text="次卡"></item>
        
<item itemID="10004" text="终身卡"></item>
    
</CardsClass>
    
<CardsClass cardclassID="30000" text="团体卡">
        
<item itemID="30001" text="家庭卡"></item>
        
<item itemID="30002" text="情侣卡"></item>
        
<item itemID="30003" text="公司卡"></item>
    
</CardsClass>
    
<CardsClass cardclassID="40000" text="VIP卡">
        
<item itemID="40001" text="VIP卡"></item>
    
</CardsClass>
</Cards>
);
        XElement xml = XElement.Load(strXmlPath);

/*方法1*/
        
//var a = from b in xml.Descendants("item")
        
//        where b.Attribute("itemID").Value.Substring(0, 2) == "10"
        
//        select new { itemID = b.Attribute("itemID").Value, itemName = b.Attribute("text").Value };

/*方法2*/

        var a
=from b in xml.Descendants("item")
               
where b.Parent.Attribute("cardclassID").Value=="10000"
               select 
new { itemID = b.Attribute("itemID").Value, itemName = b.Attribute("text").Value };

        
foreach (var n in a)
        {
            ListItem item 
= new ListItem(n.itemName, n.itemID);
        }

相关文章:

  • 2021-12-24
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-01
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-12-28
相关资源
相似解决方案