Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Collection Best Practices

Tags:

xml

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>
like image 574
Joseph Sturtevant Avatar asked Dec 17 '22 10:12

Joseph Sturtevant


1 Answers

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.

like image 153
Thomas Owens Avatar answered Dec 30 '22 21:12

Thomas Owens