Jump to content

A Basic Xml Question


Guest dglane
 Share

Recommended Posts

Guest dglane

Is the first example below valid (re the duplicate "author" elements)? Is the second example below better or more appropriate (other than for readability)? Any further explanation would be welcome. TIA<catalog>

<book>
<title>All About XML</title><author>John</author><author>Mary</author>

</book>
</catalog><catalog>

<book>
<title>All About XML</title><authors>
<name>John</name><name>Mary</name>

</authors>
</book>
</catalog>
Link to comment
Share on other sites

It depends on whatever you need to do.To actually get some information from this XML, you'll have to process it with JavaScript, PHP or something else.If you expect that applications using this XML will often need to list all authors, it's better to keep them grouped, as it will make it easy for applications to just loop over the collection, independantly from the rest of the things a "book" element might include.If you epxect that applications would rarely want to list all authors, and want to simplify processing for a single author, the first approach is better.Personally, I'd go with the second approach in this case. It would be insulting to ignore authors of a certain book, even if they aren't the "primary" ones. Therefore, I'd expect that many applications will want to loop over the full collection.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...