T
Trevor Andrew
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
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