<Sections>
<Classes>
<Class>VI</Class>
<Class>VII</Class>
</Classes>
<Students>
<Student>abc</Student>
<Student>def</Student>
</Students>
</Sections>
我必须遍历 Classes 才能将“Class”放入字符串数组中。我还必须遍历“学生”以将“学生”放入字符串数组中。
XDocument doc.Load("File.xml");
string str1;
foreach(XElement mainLoop in doc.Descendants("Sections"))
{
foreach(XElement classLoop in mainLoop.Descendants("Classes"))
str1 = classLoop.Element("Class").Value +",";
//Also get Student value
}
无法获得所有课程。此外,我需要在不使用 LINQ to XML 的情况下重写它,即使用 XmlNodeList 和 XmlNodes。
XmlDocument doc1 = new XmlDocument();
doc1.Load("File.xml");
foreach(XmlNode mainLoop in doc.SelectNodes("Sections")) ??
不知道该怎么做。