C#获取XElement的所有子元素,而不管它们的值
我有以下XML结构:C#获取XElement的所有子元素,而不管它们的值,c#,xml,linq,C#,Xml,Linq,我有以下XML结构: <init_deinit> <step name="init"> <call>...</call> <check>...</check> <call>...</call> <wait>...</wait> .... </step> <s
<init_deinit>
<step name="init">
<call>...</call>
<check>...</check>
<call>...</call>
<wait>...</wait>
....
</step>
<step name="deinit">
....
</step>
</init_deinit>
但是我需要检索“step”元素的所有子元素,并且我需要按照它们在XML中的确切顺序检索它们。所以我需要的是像IEnumerable迭代器这样的东西,它包含按此顺序调用、检查、调用和等待的元素。我试过了,但失败了:)
谢谢你的建议 这将为您提供
步骤
元素的所有子体
:
xdoc.Descendants("step").SelectMany(x => x.Descendants());
如果需要第一个步骤元素的子体
,请使用
xdoc.Descendants("step").First().Descendants();
这将为您提供步骤
元素的所有子体
:
xdoc.Descendants("step").SelectMany(x => x.Descendants());
如果需要第一个步骤元素的子体
,请使用
xdoc.Descendants("step").First().Descendants();
这将为您提供步骤
元素的所有子体
:
xdoc.Descendants("step").SelectMany(x => x.Descendants());
如果需要第一个步骤元素的子体
,请使用
xdoc.Descendants("step").First().Descendants();
这将为您提供步骤
元素的所有子体
:
xdoc.Descendants("step").SelectMany(x => x.Descendants());
如果需要第一个步骤元素的子体
,请使用
xdoc.Descendants("step").First().Descendants();
请试试这个:
XDocument xdoc = XDocument.Load("file.xml");
//Here you will get all the descendants of the first step
xdoc.Descendants("step").First().Descendants();
//To get all Descendants of step elements:
var x = xdoc.Descendants("step").Descendants();
请试试这个:
XDocument xdoc = XDocument.Load("file.xml");
//Here you will get all the descendants of the first step
xdoc.Descendants("step").First().Descendants();
//To get all Descendants of step elements:
var x = xdoc.Descendants("step").Descendants();
请试试这个:
XDocument xdoc = XDocument.Load("file.xml");
//Here you will get all the descendants of the first step
xdoc.Descendants("step").First().Descendants();
//To get all Descendants of step elements:
var x = xdoc.Descendants("step").Descendants();
请试试这个:
XDocument xdoc = XDocument.Load("file.xml");
//Here you will get all the descendants of the first step
xdoc.Descendants("step").First().Descendants();
//To get all Descendants of step elements:
var x = xdoc.Descendants("step").Descendants();