linq to xml求解,急急急
<?xml version="1.0" encoding="utf-8"?>
<WorkflowVml>
<BtnList id="5" >
<BtnSingle id="A001" name="001" defaultUrl="xxx.aspx" ></BtnSingle>
<BtnSingle id="A002" name="002" defaultUrl="xxx.aspx" ></BtnSingle>
<BtnSingle id="A003" name="003" defaultUrl="xxx.aspx" ></BtnSingle>
<BtnSingle id="A004" name="004" defaultUrl="xxx.aspx" ></BtnSingle>
</BtnList>
<BtnList id="7" >
<BtnSingle id="B001" name="001" defaultUrl="xxx.aspx" tar="rightFrame" ></BtnSingle>
<BtnSingle id="B002" name="002" defaultUrl="xxx.aspx" tar="rightFrame" ></BtnSingle>
<BtnSingle id="B003" name="003" defaultUrl="xxx.aspx" tar="rightFrame" ></BtnSingle>
<BtnSingle id="B004" name="004" defaultUrl="xxx.aspx" tar="rightFrame" ></BtnSingle>
</BtnList>
</WorkflowVml>
XDocument RoAuXml = XDocument.Load(Server.MapPath("Competence.xml"));
var roauList = from roau in RoAuXml.Descendants("BtnList")
where roau.FirstAttribute.Value == "7"
select roau.Elements("BtnSingle");
然后我不知道怎么从roauList里面把BtnSingle的id,name,defaulturl这些读出来呢?
------最佳解决方案-------------------- foreach (var item in roauList)
{
foreach (var item1 in item)
{
Console.WriteLine("id:{0},name:{1},defaulturl:{2}",
item1.Attribute("id").Value,
item1.Attribute("name").Value,
item1.Attribute("defaulturl").Value);
}
}
------其他解决方案--------------------未将对象引用设置到对象的实例------其他解决方案--------------------
XDocument RoAuXml = XDocument.Load("c:\\1.txt");
var roauList = from roau in RoAuXml.Descendants("BtnList")
where roau.FirstAttribute.Value == "7"