Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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.
 
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





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 10:25 AM
XML parsing, hierarchy?! saebe Beginning VB 6 0 February 27th, 2006 12:17 PM
How do you represent thumbnails and image maps? mountainbiker XSLT 0 June 17th, 2004 07:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.