【发布时间】:2023-03-12 14:34:01
【问题描述】:
<tests>
<test id ="1">
<name> peter </name>
<age> 23 </age>
<informations> bla bla </informations>
</test>
<test id ="41">
<name> besd </name>
<age> 54 </age>
<informations> some other text </informations>
</test>
<test id ="57">
<name> john </name>
<age> 61 </age>
<informations> vintage </informations>
</test>
<test id ="67">
<name> claude </name>
<age> 11 </age>
<informations> motivation </informations>
</test>
</tests>
我设法在XDocument xInformations 中获取了上述所有信息。
List<string> testIds = new List<string>();
testIds = xInformations.Descendants("test").Select(x => (string)x.Attribute("id")).ToList();
现在,我确实想使用foreach 来读取并保存每个 id 的所有信息:
foreach (string extId in testIds.Distinct())
{
/// how can I take step by step the name, age, informations for all test cases ?
}
我怎样才能做到这一点?
【问题讨论】:
-
我没有找到使用 XDocument
-
啊,对不起:)
-
@FlorinM。您在下图中看到了它从属性中获取值的图像。我被检查了你的确切例外是什么。