Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#获取XElement的所有子元素,而不管它们的值_C#_Xml_Linq - Fatal编程技术网

C#获取XElement的所有子元素,而不管它们的值

C#获取XElement的所有子元素,而不管它们的值,c#,xml,linq,C#,Xml,Linq,我有以下XML结构: <init_deinit> <step name="init"> <call>...</call> <check>...</check> <call>...</call> <wait>...</wait> .... </step> <s

我有以下XML结构:

<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();