Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring Relational Data in XML
    primarykey
    data
    text
    <p>I'm wondering what the best practices are for storing a relational data structure in XML. Particulary, I am wondering about best practices for enforcing node order. For example, say I have three objects: <code>School</code>, <code>Course</code>, and <code>Student</code>, which are defined as follows:</p> <pre><code>class School { List&lt;Course&gt; Courses; List&lt;Student&gt; Students; } class Course { string Number; string Description; } class Student { string Name; List&lt;Course&gt; EnrolledIn; } </code></pre> <p>I would store such a data structure in XML like so:</p> <pre><code>&lt;School&gt; &lt;Courses&gt; &lt;Course Number="ENGL 101" Description="English I" /&gt; &lt;Course Number="CHEM 102" Description="General Inorganic Chemistry" /&gt; &lt;Course Number="MATH 103" Description="Trigonometry" /&gt; &lt;/Courses&gt; &lt;Students&gt; &lt;Student Name="Jack"&gt; &lt;EnrolledIn&gt; &lt;Course Number="CHEM 102" /&gt; &lt;Course Number="MATH 103" /&gt; &lt;/EnrolledIn&gt; &lt;/Student&gt; &lt;Student Name="Jill"&gt; &lt;EnrolledIn&gt; &lt;Course Number="ENGL 101" /&gt; &lt;Course Number="MATH 103" /&gt; &lt;/EnrolledIn&gt; &lt;/Student&gt; &lt;/Students&gt; &lt;/School&gt; </code></pre> <p>With the XML ordered this way, I can parse <code>Courses</code> first. Then, when I parse <code>Students</code>, I can look up each <code>Course</code> listed in <code>EnrolledIn</code> (by its <code>Number</code>) in the <code>School.Courses</code> list. This will give me an object reference to add to the <code>EnrolledIn</code> list in <code>Student</code>. If <code>Students</code>, however, comes <em>before</em> <code>Courses</code>, such a lookup to get a object reference is not possible. (Since <code>School.Courses</code> has not yet been populated.)</p> <p>So what are the best practices for storing relational data in XML? - Should I enforce that <code>Courses</code> must always come before <code>Students</code>? - Should I tolerate any ordering and create a stub <code>Course</code> object whenever I encounter one I have not yet seen? (To be expanded when the definition of the <code>Course</code> is eventually reached later.) - Is there some other way I should be persisting/loading my objects to/from XML? (I am currently implementing <code>Save</code> and <code>Load</code> methods on all my business objects and doing all this manually using <code>System.Xml.XmlDocument</code> and its associated classes.)</p> <p>I am used to working with relational data out of SQL, but this is my first experience trying to store a non-trivial relational data structure in XML. Any advice you can provide as to how I should proceed would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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