I’m trying to store some information using XML, what would be the correct method for grouping the data?
I have multiple computers in three rooms, should I create a room element or use an attribute?
<rooms>
<room name="Room 1">
<computer>
<name>Student14</name>
<ipaddress>00.00.00.01</ipaddress>
<macaddress>00-0B-DB-74-12-AB</macaddress>
</computer>
</room>
<room name="Room 2">
<computer>
<name>Student15</name>
<ipaddress>00.00.00.02</ipaddress>
<macaddress>00-0B-DB-74-12-AC</macaddress>
</computer>
</room>
<room name="Room 3">
<computer>
<name>Student16</name>
<ipaddress>00.00.00.03</ipaddress>
<macaddress>00-0B-DB-74-12-AD</macaddress>
</computer>
</room>
</rooms>
Or like this:
<computers>
<computer>
<name>Student14</name>
<ipaddress>00.00.00.01</ipaddress>
<macaddress>00-0B-DB-74-00-AC</macaddress>
<location>Room 1</location>
</computer>
<computer>
<name>Student15</name>
<ipaddress>00.00.00.02</ipaddress>
<macaddress>00-0B-DB-74-00-AB</macaddress>
<location>Room 2</location>
</computer>
<computer>
<name>Student16</name>
<ipaddress>00.00.00.03</ipaddress>
<macaddress>00-0B-DB-74-00-AD</macaddress>
<location>Room 3</location>
</computer>
</computers>
Depends on what data you are concerned with. Do you want to store information about rooms or computers? In your first example, you are storing information about rooms. This could also include couches, lamps, etc. In your second, you are storing information about computers. This could include their location, model, etc.
It depends on what you want the information to be about.