如何使linq到xml查询 [英] how to make linq to xml query
本文介绍了如何使linq到xml查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个xml文件。
i have an xml file.
<?xml version="1.0" encoding="utf-8" ?>
<Vehicle>
<feature id = "1" name = "car">
<propery id = "1" name = "Model Number"/>
<property id = "2" name = "Color of car"/>
</feature>
<feature id = "2" name = "Bike">
<property id = "1" name = "Model of bike"/>
<property id ="2" name = "Compnay name"/>
</feature>
</vehicle>
i想要搜索属性元素名称= car的名称。
i want to search name of property element where feature name = car.
var Parameteroffeature = from xp in xelement.Elements("property")
select xp.Attributes("name").Where()
请有人帮助我。
谢谢
please anyone help me.
thanks
推荐答案
您好b $ b
试试此代码..
我使用了lamda表达式而不是理解查询。
Hi
Try this code..
I have used lamda expression instead of comprehension queries.
XDocument xdoc = XDocument.Load("xmlfile.xml");
var lv1ss = xdoc.Descendants("Vehicle").Descendants("feature").Select(k => new
{
propertyid = k.Descendants("propery").Select(a => new
{
propertyid = a.Attribute("id").Value,
propertyname = a.Attribute("name").Value
}).ToList(),
id = k.Attribute("id").Value,
name = k.Attribute("name").Value
}).Where(k => k.name == "car").ToList();
LINQ to XML [ ^ ]
查看Linq查询:
http://www.dreamincode.net/forums/topic/218979-linq-to-xml/ [ ^ ]
see this for Linq Queries:
http://www.dreamincode.net/forums/topic/218979-linq-to-xml/[^]
这篇关于如何使linq到xml查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文