我有一个类似于这样的 xml 结构:
<cars>
<car>
<make>Ford</make>
<model>F-150</model>
<year>2011</year>
<customs>
<customAttribute>Color</customAttribute>
<customValue>Black</customValue>
<customAttribute>Doors</customAttribute>
<customValue>2</customValue>
</customs>
</car>
</cars>
我想以如下所示的方法返回汽车列表:
return (from car in cars.Descendants("car")
select new Car {
Make = car.Element("make").Value,
Model = car.Element("model").Value,
Year = car.Element("year").Value
Color = ?????,
Doors = ?????
});
如何填充颜色和门字段?我需要为适当的 customValue 节点获取 customAttribute 值。
不太清楚如何做到这一点。
非常感谢!