[XML-SIG] A bit off topic: XML advice needed...

Stuart Hungerford stuart.hungerford@webone.com.au
Wed, 3 Mar 1999 21:07:06 +1100


Hi all,

This is the text of a message I posted earlier to 
comp.text.xml.  Since the people on this list are 
such nice folks, I thought I'd ask your opinions
too.

I apologize in advance for an off-topic posting,
but good from-the-trenches XML advice is hard 
to find.

-------------------------------------------------------------

I have a question about designing XML DTD's that I suspect 
shows me trying to think of XML too much like a programming
language, and not enough like a markup language.

Anyways, suppose I have a DTD that describes elements for
dates, and in particular the <date> element. Now suppose I 
want to re-use my <date> element definition in a DTD for
marking up "events".  Each event has a start date and end
date. (Please forgive any terminology errors here).

My first mental reaction (in a sort of pseudocode is):

     class date
     {
         ...
     };


     class event
     {
         start_date : date;
         end_date : date;
     };

But how to express the XML equivalent?  One way would be:

    Use an external ENTITY to textually include the date.dtd in
    events.dtd and define

            <!ELEMENT event (start-date, end-date)>
            <!ELEMENT start-date (date)>
            <!ELEMENT end-date (date)>

    That way I get self-documenting names for the date elements, 
    but at the cost of another level of markup needed for each date 
    in all my XML documents that use events.dtd.

I could also:

    Use an external ENTITY to textually include the date.dtd in
    events.dtd and define:

            <!ELEMENT event (date, date)>
            <!ATTLIST date role (start | end) #REQUIRED>
            
    That way I can create markup like:
          <event> <date role="start">...</date> ... </event>

     But now I have to check in an application whether there's
     exactly one start and end etc--I seem to have given up some
     validity checking benefits for a level of markup tags.

There's probably lots of other ways to do this--the question is,
which are the "good" ways, where "good" in my case means 
I can re-use existing definitions and still come out with a 
DTD and documents that are not too hard to understand.

I guess I'm looking for the gang-of-four patterns book for
XML, but in the meantime can anyone share their wisdom 
and experiences on this issue?