Note that there are some explanatory texts on larger screens.

plurals
  1. POlocal XML to Listbox in c#
    text
    copied!<p>There are some clases:</p> <pre><code>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; } </code></pre> <p>And:</p> <pre><code> public class StudentBody : INotifyPropertyChanged { private string school; ObservableCollection&lt;Student&gt; students = new ObservableCollection&lt;Student&gt;(); public string School { ... } public ObservableCollection&lt;Student&gt; 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; } </code></pre> <p>I'm trying to put the names of the students to listboks:</p> <pre><code> ObservableCollection&lt;StudentBody&gt; StudentBody = new ObservableCollection&lt;StudentBody&gt;(); XmlSerializer serializer = new XmlSerializer(typeof(StudentBody)); XmlReader reader = XmlReader.Create(@"XMLFile1.xml"); StudentsList.ItemsSource = StudentBody; </code></pre> <p>from tnis XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;StudentBody xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;School&gt;El Paso High School&lt;/School&gt; &lt;Students&gt; &lt;Student&gt; &lt;FullName&gt;Adkins Bowden&lt;/FullName&gt; ... &lt;/Student&gt; &lt;Student&gt; ... &lt;/Student&gt; &lt;Student&gt; ... &lt;/Student&gt; &lt;/Students&gt; &lt;/StudentBody&gt; </code></pre> <p>But in the end I receive an error </p> <blockquote> <p>Could not find schema information for the element 'StudentBody'.</p> </blockquote> <p>What am I doing wrong and how to put the data in listboks?</p> <p>EDIT:</p> <pre><code>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; } } </code></pre> <p>error: There is an error in XML document (0, 0).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload