如何使用Linq with Nested Descendants读取XML

时间:2014-02-17 07:00:49

标签: c# linq

如何读取LINQ

中嵌套后代内的元素

我的Xml文件格式

<SmPpProperties>
 <PpProperties>
   <Project Name="CEESI all 2" CreatedDate="2013-11-18T16:48:54.9452592+01:00" ModifiedDate="2013-11-18T16:48:57.2413905+01:00">
      <NuclearSystem>Barium</NuclearSystem>
      <TimeLine>
          <Clip>
            <FilePathFP>FPS\FP001D\Default-wp000-15Oct2012-105001.vxbin</FilePathFP>
          </Clip>
      </TimeLine>
   </Project>
  </PpProperties>
</SmPpProperties>

我正在尝试使用C#代码

var SmPpProperties
      = from PpProperties in xmldoc.Descendants("PpProperties")
        select new
        {
            from Project in xmldoc.Descendants("Project ")
            select new { 
           *How to proceed*

1 个答案:

答案 0 :(得分:0)

var SmPpProperties = from poj in xmldoc.Descendants("Project")
                     select new {name = poj.Attribute("Name"), 
                                 filePath = poj.Element("TimeLine").Element("Clip").Element("FilePathFP").Value};

 foreach (var item in SmPpProperties)
 {
     Console.WriteLine("Name = {0}, File Path = {1}", item.name, item.filePath);
 }