Code
<?xml version="1.0" encoding="utf-8" ?>
<Cards>
<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>
<?xml version="1.0" encoding="utf-8" ?>
<Cards>
<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>
Code
string strXmlPath = System.Web.HttpContext.Current.Server.MapPath("Stadium_card.xml");
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);
}
string strXmlPath = System.Web.HttpContext.Current.Server.MapPath("Stadium_card.xml");
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);
}