我有以下 XML 代码:
<Presets>
<Preset ID="0" Name="aaaa">
<IncludedChampions>
<ID>5</ID>
<ID>6</ID>
<ID>7</ID>
</IncludedChampions>
</Preset>
<Preset ID="1" Name="some">
<IncludedChampions>
<ID>4</ID>
<ID>5</ID>
<ID>6</ID>
</IncludedChampions>
</Preset>
</Presets>
我试图用这个来解析它:
XmlReader reader = XmlReader.Create("./config.xml");
while (reader.Read())
{
while (reader.ReadToFollowing("Preset"))
{
presetList.Add(new Preset());
presetList[presetList.Count - 1].name = reader.GetAttribute(1);
Console.WriteLine("Preset list ID " + Convert.ToString(presetList.Count - 1));
while (reader.ReadToFollowing("ID"))
{
Console.WriteLine("Champion ID " + reader.ReadElementContentAsString());
}
}
}
但在输出中,我只看到“预设列表 ID 0”,然后是所有 ID。另一个预设 ID 去哪儿了?谢谢!