I'm creating an application that will store a hierarchical collection of items in an XML file and I'm wondering about the industry standard for storing collections in XML. Which of the following two formats is preferred? (If there is another option I'm not seeing, please advise.)
Option A
<School>
<Student Name="Jack" />
<Student Name="Jill" />
<Class Name="English 101" />
<Class Name="Math 101" />
</School>
Option B
<School>
<Students>
<Student Name="Jack" />
<Student Name="Jill" />
</Students>
<Classes>
<Class Name="English 101" />
<Class Name="Math 101" />
</Classes>
</School>
I'm no XML expert, but I find Option B to be more human readable, and I think it's just as machine readable as Option A. I believe that XML is designed to be both human and machine readable, so I would go for Option B myself.
I just realized something else after Ryan Farley's post. If the Students or Classes section becomes too big and must be moved to another XML file, it seems like it would be easier to copy the node and create a new XML file out of that node with Option B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With