Jump to content
Sign in to follow this  
Guest dglane

A Basic Xml Question

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>

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...