XML Build Recommendations

I am creating an application that will store a hierarchical set of elements in an XML file, and I wonder what industry standard stores collections in XML. Which of the following two formats is preferred? (If there is another option that I do not see, please let me know.)

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> 
+4
source share
4 answers

I am not an XML expert, but I find option B more human-readable, and I think it is machine-readable as option A. I believe XML is for both human and machine-readable, so I would go for option B. yourself.


I just realized something else after recording Ryan Farley. If the โ€œStudentsโ€ or โ€œClassesโ€ section gets too large and needs to be moved to another XML file, it seems like it would be easier to copy the node and create a new XML file from this node with option B.

+4
source

Definitely option B.

I would not mix students and classes in XML in the same way I would not mix students and classes in one table in the database.

+4
source

Option B , absolutely. When there is a logical grouping of similar elements, it must have a parent element. Thus, my parser does not have to go through all 500 student record entries to see if there are mixed class entries.

+2
source

Another compelling reason to use option B is error checking. If the source file is modified outside of the XML application, or if the XSD scheme is not applied, there may be times when you have an odd number of students and classes.

At the very least, if you have students and classes grouped together, you can easily find out if each record is complete regardless of any other record.

+2
source

Source: https://habr.com/ru/post/1276412/


All Articles