-3

我的问题是 Xml 文件,要查看:这是行不通的。

IEnumerable<XElement> stepsList = doc.Elements();

XML 文件

<OneGoal>
<Goal>100000</Goal>
<StepOne>ewewewe</StepOne>
<StepTwo>wee</StepTwo>
<StepThree>MY</StepThree>
<StepFour>wwwww</StepFour>
<StepFive>ddddw</StepFive>
<StepSix>fcd</StepSix>
<StepSeven>blblblfl</StepSeven>
<StepEight>z dwadddddsssssssssssss</StepEight>
<StepNine>radwds</StepNine>
<StepTen>
 blblblblblblb
</StepTen>
<DateDay>18</DateDay>
<DateMonth>7</DateMonth>
<DateYear>2019</DateYear>
</OneGoal>

我想要所有元素到 IEnumberable 。早些时候,所有元素都有名称“步骤”。

4

2 回答 2

2

如何将您的平面 xml 转换为Dictionary<string,string>

var dict = XDocument.Parse(xml)
           .Element("OneGoal")
           .Elements()
           .ToDictionary(e => e.Name.LocalName, e => e.Value);

Console.WriteLine(dict["StepOne"]);
于 2013-04-28T19:02:02.850 回答
1

用于XDocument从文件加载或从字符串解析。

var stepList = doc.Descendants();
于 2013-04-28T19:01:30.660 回答