1

いくつかのクラスがあります:

public class Student : INotifyPropertyChanged
    {
        string fullName;
        string firstName;
        string middleName;
        string lastName;
        string sex;
        string photoFilename;
        decimal gradePointAverage;

        public string FullName
        {
            set
            {
                if (fullName != value)
                {
                    fullName = value;
                    OnPropertyChanged("FullName");
                }
            }
            get
            {
                return fullName;
            }
        }

...
        protected virtual void OnPropertyChanged(string propChanged)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
        }
        public event PropertyChangedEventHandler PropertyChanged;
}

と:

        public class StudentBody : INotifyPropertyChanged
        {
            private string school;
            ObservableCollection<Student> students = new ObservableCollection<Student>();
            public string School
            {
...
            }
            public ObservableCollection<Student> Students
            {
                set
                {
                    if (students != value)
                    {
                        students = value;    
                    }
                }
                get
                {
                    return students;
                }
            }

            private void NotifyPropertyChanged(string propertyName)
            {
                if (null != PropertyChanged)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
            public event PropertyChangedEventHandler PropertyChanged;

        }

生徒の名前をリストボックスに入れようとしています:

    ObservableCollection<StudentBody> StudentBody = new ObservableCollection<StudentBody>();
    XmlSerializer serializer = new XmlSerializer(typeof(StudentBody));
    XmlReader reader = XmlReader.Create(@"XMLFile1.xml");
    StudentsList.ItemsSource = StudentBody;

tnis XML から:

<?xml version="1.0" encoding="utf-8"?>
<StudentBody xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <School>El Paso High School</School>
  <Students>
    <Student>
      <FullName>Adkins Bowden</FullName>
      ...
    </Student>
    <Student>
      ...
    </Student>
    <Student>
      ...
    </Student>
  </Students>
</StudentBody>

しかし、最終的に私はエラーを受け取ります

要素 'StudentBody' のスキーマ情報が見つかりませんでした。

私は何が間違っていて、データをリストボックスに入れる方法を教えてください。

編集:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    using (var istream = new IsolatedStorageFileStream("XMLFile1.xml", FileMode.OpenOrCreate, store))
    {
        XmlSerializer xml = new XmlSerializer(typeof(StudentBody));
        StudentBody StudentBody = xml.Deserialize(istream) as StudentBody; // here error
        StudentsList.ItemsSource = StudentBody.Students;
    }
}

error: XML 文書にエラーがあります (0, 0)。

4

1 に答える 1