xml structure question

A

andy

say i currently have xml like so...

<node>
<Date>20080507</Date>
<ChildNode />
<ChildNode />
</node>
<node>
<Date>20080507</Date>
<ChildNode />
<ChildNode />
</node>
etc...

And I know that later i want to group by the date (either using xslt or
after importing the xml data into another format)

would it be better to have the date as the master node ?, like for
example...

<Date date="20080507">
<node>
<ChildNode />
<ChildNode />
</node>
<node>
<ChildNode />
<ChildNode />
</node>
</Date>

Are there any good guides on how and why to structure xml documents ?

any help appreciated.
 
J

Joseph J. Kesselman

Are there any good guides on how and why to structure xml documents ?

It's very much like constructing data structures in programming
languages or databases; most of the same best-practices apply.
In general, you should structure to capture the semantics (meaning) that
your data is intended to express, and/or tune it to suit the most common
usage... and sometimes, especially early on, to make most sense to the
human trying to debug the system.

Note that converting between these two ways of organizing the data isn't
hard. Lots of examples exist.
 
A

andy

Joseph said:
It's very much like constructing data structures in programming
languages or databases; most of the same best-practices apply.
In general, you should structure to capture the semantics (meaning) that
your data is intended to express, and/or tune it to suit the most common
usage... and sometimes, especially early on, to make most sense to the
human trying to debug the system.

Note that converting between these two ways of organizing the data isn't
hard. Lots of examples exist.

your right, I was a little vague.

Lets say I want to create a xsl file to go with the xml file that will
group the data by date, perhaps even have some funky java script that
will group data by one of the child nodes as well

<node>
<Date>20080507</Date>
<Pattern>pattern1</Pattern>
<ChildNode />
</node>
<node>
<Date>20080507</Date>
<Pattern>pattern1</Pattern>
<ChildNode />
</node>

then the resulting html document would look something like


20080507

+patern1 // this will be clickable and collapsable, when expanded you
can see all the data for the child nodes which


any help appreciated.
 
J

Joseph J. Kesselman

You can work from either representation. (One of XSLT's advantages over
CSS is that the output document's structure can be completely different
from that of the input.) The question is one of how you're generating
the document and what else you're doing with it. There are certainly
some forms which will be easier for this particular XSLT stylesheet to
process, but they may not be easier for your other needs. Beware of
optimizing for only one case.

If your stylesheet needs to gather things with the same date, you might
want to examine the "grouping" section of the XSLT FAQ:

http://www.dpawson.co.uk/xsl/sect2/N4486.html
 
P

Peter Flynn

andy said:
Are there any good guides on how and why to structure xml documents ?

There is a lot of excellent stuff about this in Eve Maler and Jeanne El
Andaloussi's book "Writing SGML DTDs" (95% of which remains valid for
XML: just ignore the SGL bits).

///Peter
 
A

andy

Joseph said:
You can work from either representation. (One of XSLT's advantages over
CSS is that the output document's structure can be completely different
from that of the input.) The question is one of how you're generating
the document and what else you're doing with it. There are certainly
some forms which will be easier for this particular XSLT stylesheet to
process, but they may not be easier for your other needs. Beware of
optimizing for only one case.

If your stylesheet needs to gather things with the same date, you might
want to examine the "grouping" section of the XSLT FAQ:

http://www.dpawson.co.uk/xsl/sect2/N4486.html

Thanks for your replies. I guess I was looking to try and make it so
the javascript is as easy to write as possible, your advice has been
very helpful.
 
J

Joseph J. Kesselman

andy said:
Thanks for your replies. I guess I was looking to try and make it so
the javascript is as easy to write as possible

That's as reasonable a primary design goal as any other. It's up to you
to decide whether that's the right thing to optimize for.

As with any programming problem, there are multiple solutions that work.
Which one's best depends on what's most important to you.

My personal inclination would be to start with the first approach, where
each record carries its own date, and to generate the gathered-by-date
version from that if/when needed. But that assumes the nodes, rather
than the dates, are the thing you consider your most basic unit of
information. For other applications, the Date may really be the primary
chunk of data and the second approach would be better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top