Xml出勤率:所选学生的出勤率c#

时间:2013-10-07 16:08:20

标签: c# xml

我有点麻烦。这就是我的xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Students xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xsi:noNamespaceSchemaLocation="student.xsd">
<Student>
<StudentID>001</StudentID>
<FirstN>John</FirstN>
<LastN>Doe</LastN>
<Seat>A1</Seat>
<PresentOn>10/7/2013 8:55:52 AM</PresentOn>
<PresentOn>10/7/2013 8:55:52 AM</PresentOn>
<PresentOn>10/7/2013 8:55:52 AM</PresentOn>
</Student>
<Student>
<StudentID>001</StudentID>
<FirstN>Jane</FirstN>
<LastN>Doe</LastN>
<Seat>A2</Seat>
<PresentOn>10/7/2013 8:55:52 AM</PresentOn>
<PresentOn>10/7/2013 8:55:52 AM</PresentOn>
<PresentOn>10/7/2013 8:55:52 AM</PresentOn>
</Student>
</Students>

对于特定的学生来说,我没有问题,Jane Doe说,但是当我尝试输出PresentOn日期时,只有第一个显示在richtextbox上。我已将.xsd上的PresentOn元素设置为能够多次出现,如果有任何帮助的话。

我将如何输出所有她的PresentOn日期而不仅仅是一个,我正在使用XmlNodelist foreach(XmlNodelist中的XmlNode节点)并找到学生并且我能够输出第一个日期,但是没有想法如何不止一次输出PresentOn。

这是我用来找到学生的代码:

XmlDocument students = new XmlDocument();
        students.Load(@"C:\SeatingChart\StudentCopy.xml");
        XmlNodeList studentID = students.SelectNodes("Students/Student");
        //user chooses student id from combobox
        string stuID = removeTextBoxSpace(comboBox1.GetItemText(comboBox1.SelectedItem));

        foreach (XmlNode node in studentID)
        {
            try
            {
                string xmlID = node["StudentID"].InnerText.ToString();

                if (stuID.Equals(xmlID))
                {
                    //Messagebox showing the students name to verify correct student

                      string preson = node["PresentOn"].InnerText.ToString();
                      richTextBox1.AppendText("Present on: " + preson.ToString() + "\n");
                }

到目前为止,这就是我所拥有的全新内容,还有很多需要学习的内容。

0 个答案:

没有答案
相关问题