<Sections>
<Classes>
<Class>VI</Class>
<Class>VII</Class>
</Classes>
<Students>
<Student>abc</Student>
<Student>def</Student>
</Students>
</Sections>
我需要循环遍历Classes以将“Class”放入字符串数组中。 我还需要循环遍历“Students”以将“Student”放入字符串数组中。
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")) ??
不确定如何开始。