【发布时间】:2017-09-19 13:48:15
【问题描述】:
LINQ 读取 XML
下面是我的 *.xml 文件,它有两个部分:
<sections>
<section guid="112ff6b8-2609-4d19-b774-33ab951ee66a" last_change="1970-01-01T00:00:00.000" action="added"
name="Concrete sections, Rectangle, 150x300" type="custom" fd-mat="3" fd_name_code="Concrete sections"
fd_name_type="Rectangle" fd_name_size="150x300">
<region_group>
<region>
<contour>
<edge type="line">
<point x="-0.075" y="-0.15" z="0"></point>
<point x="0.075" y="-0.15" z="0"></point>
<normal x="0" y="1" z="0"></normal>
</edge>
<edge type="line">
<point x="0.075" y="-0.15" z="0"></point>
<point x="0.075" y="0.15" z="0"></point>
<normal x="-1" y="0" z="0"></normal>
</edge>
<edge type="line">
<point x="0.075" y="0.15" z="0"></point>
<point x="-0.075" y="0.15" z="0"></point>
<normal x="0" y="-1" z="0"></normal>
</edge>
<edge type="line">
<point x="-0.075" y="0.15" z="0"></point>
<point x="-0.075" y="-0.15" z="0"></point>
<normal x="1" y="0" z="0"></normal>
</edge>
</contour>
</region>
</region_group>
<end></end>
</section>
<section guid="98948ace-afb2-400d-9d96-752f5fce40c4" last_change="1970-01-01T00:00:00.000" action="added"
name="Concrete sections, Rectangle, 300x600" type="custom" fd-mat="3" fd_name_code="Concrete sections"
fd_name_type="Rectangle" fd_name_size="300x600">
<region_group>
<region>
<contour>
<edge type="line">
<point x="-0.15" y="-0.3" z="0"></point>
<point x="0.15" y="-0.3" z="0"></point>
<normal x="0" y="1" z="0"></normal>
</edge>
<edge type="line">
<point x="0.15" y="-0.3" z="0"></point>
<point x="0.15" y="0.3" z="0"></point>
<normal x="-1" y="0" z="0"></normal>
</edge>
<edge type="line">
<point x="0.15" y="0.3" z="0"></point>
<point x="-0.15" y="0.3" z="0"></point>
<normal x="0" y="-1" z="0"></normal>
</edge>
<edge type="line">
<point x="-0.15" y="0.3" z="0"></point>
<point x="-0.15" y="-0.3" z="0"></point>
<normal x="1" y="0" z="0"></normal>
</edge>
</contour>
</region>
</region_group>
<end></end>
</section>
作为结果我希望从上面两个部分中选择(guid, fd_name_size),如下图
112ff6b8-2609-4d19-b774-33ab951ee66a,150x300
98948ace-afb2-400d-9d96-752f5fce40c4, 300x600
这是我的 C# 代码
string a1 = "will be guid"; string a2 = "will be fd_name_size"; // to test
var secBC = from lv1 in xDoc.Descendants("section")
select new
{
Header = lv1.Attribute("guid").Value
// How to select "fd_name_size" ????
};
foreach (var lv1 in secBC)
{
a1 = lv1.Header;
}
我只得到'guid'(作为a1)但不知道如何选择'fd_name_size'。请帮忙:o)
【问题讨论】:
标签: c# linq-to-xml