Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 21st, 2003, 07:10 AM
Registered User
 
Join Date: Jul 2003
Location: Melbourne, VIC, Australia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML Document Design to represent a Hierarchy

Hi There,

I was wanting some advice regarding the best-practice approach to
representing a hierarchy in XML. Let me explain by an example of the two
different approaches I have seen.

In the first example all of the data in the document is enclosed within what
might be an ambiguous <categories> node. However on some occasions there
might be some need for this node to have some attributes. And then for
individual <category> nodes within that, they again have a <categories> node
within which child <category> nodes exist.

In the second example, the <categories> nodes are eliminated and hierarchy
is represented simply by there being <category> nodes within <category>
nodes.

Example 1

<root>
<categories>
    <category>
        ...
    </category>
    <category>
        ...
        <categories>
            <category> ... </category>
            <category> ... </category>
        </categories>
    <category>
</categories>
</root>

Example 2

<root>
<category>
    ...
</category>
<category>
    ...
    <category>
    </category>
    <category>
    </category>
</category>
</root>

What I would like guidance on is which approach would be considered
"best-practice", or are both valid in different circumstances? Additionally,
does anyone have some good references on where I could research these XML
design issues further? Are there any ramifications with regard to writing an
XSD schema for such document?

Thanks in Advance,
Trevor Andrew
Reply With Quote
  #2 (permalink)  
Old August 12th, 2003, 06:58 PM
Authorized User
Points: 251, Level: 5
Points: 251, Level: 5 Points: 251, Level: 5 Points: 251, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Canada.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Goddang Trevor!

Could you be less clear? It's so illuminating that I have to put sunglasses on!

IF I understand what you're trying to say, my advice would be to try to abstract all you can. <categories> enclosing many <category> elements seems fine with me. However, I don't think it's a great idea to allow <categories> elements and <category> elements to be siblings. IMHO this is an abstraction error. But, you can do all you want, as long as it fits your needs ;o)

Good luck!

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
Reply With Quote
  #3 (permalink)  
Old August 15th, 2003, 08:47 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your example 2 gives a flatter hierarchy and would generally be the best and most compact (each extra tag adds size and processing overhead).

However, you may want to include collection elements (such as your <categories> if you need to group sub-elements because:

- you need to qualify some of the sub-elements by a common attribute (or multiple common sub-elements), or

- you want to be able to visually inspect the file (in IE say) and a jumble of sub-elements is too confusing.


I find one of the helpful methods of analysing data structures is that used for normalising relational database structures.

Also the object-oriented inheritance tree design process help too. That is:
- Bubble commonality as high up the tree as you can, and
- Sediment differences as low in the tree as you can

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Document design mode image dont show in IE7 h2c357 Javascript 0 May 3rd, 2007 09:21 AM
Flat DB structure into XML Hierarchy DaveQuested XSLT 1 January 29th, 2007 09:25 AM
XML parsing, hierarchy?! saebe Beginning VB 6 0 February 27th, 2006 11:17 AM
How do you represent thumbnails and image maps? mountainbiker XSLT 0 June 17th, 2004 07:22 AM



All times are GMT -4. The time now is 07:59 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.