tags:

views:

16

answers:

2

Hi,

I want to create an xml document that has multiple instance of a type, not sure what's the proper way to do this:

<farm>
  <horses>
    <horse name="jo"></horse>
    <horse name="bill"></horse>
  </horses>
</farm>

or should I skip the tag and just do this:

<farm>
  <horse name="jo"></horse>
  <horse name="bill"></horse>
</farm>

which way is correct?

Thanks

+1  A: 

It's xml, you're free to choose whatever you like best :)

Seriously - both are ok; but think about who you want to please.

As a programmer that would need to consume XML, I would like the first form better. As an editor that would need to manually create XML I would like the second form better.

I guess i would probably settle for the first form.

Roland Bouman
Ok cool I will go with the first choice since I am going to be parsing it, thanks.
Ok, good! If you want to open another can of worms, ask what is best, using an attribute for the `<horse>`'s name, or an attribute like you do now :)
Roland Bouman
uhm...I mean, "a *child element* or an attribute", sorry my bad.
Roland Bouman
A: 

I fail to see how way 1 is better than way 2.

Since there is a separate type (that is, separate node name) for horses, an additional wrapper, horses, does not make much sense to me. It would, it horses needed to be separated into several groups, say, horsesToKeep and horsesToSell.

GSerg
Format 1 clearly puts all the horses together and makes it clear that they belong together. Format 2 suggests that it may be possible to have one `horse`, followed by one `cow`, and then another `horse`.
John Saunders