对上面的朋友答复做一点补充:
XDocument doc = XDocument.Parse(xml);
var list = (from node in doc.Root.Descendants("FcCom")
where node.Attribute("scompany")!=null
select node.Attribute("scompany").Value).Take(12);
如果要加上排序,分页等,你可以再自己看看OrderBy()和Skip()方法。
用XmlSerializer反序列化得到FcCom列表,然后取出前12个。XmlSerializer怎么用搜一下就有了。给你个例子吧:
XmlSerializer xs=new XmlSerializer(typeof(Person));
Stream stream = new FileStream("c:\\xxx.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Person p=(Person)xs.Deserialize(stream);
用foreach循环,加个count判断下就OK了
linq to xml
string xml =
@"<data>
<FcCom id=""75"" company=""啊啊"" scompany=""上社产"" />
<FcCom id=""4"" company=""发有限公司"" scompany=""联泰房产"" />
<FcCom id=""3"" company=""公司汕头公司"" scompany=""中信房产"" />
</data>";
XDocument doc = XDocument.Parse(xml);
var list = from node in doc.Root.Descendants("FcCom")
select node.Attribute("scompany").Value;
foreach (var attr in list)
{
Console.WriteLine(attr);
}