Need opinion on DTD design

  • Thread starter stefan.rickfjord
  • Start date
S

stefan.rickfjord

Hi,

I am a newbie to programming using XML and I'm currently working on a
side-project which will house some database information in a XML-file.
I am writing a DTD to specify the XML-format, mostly for the purpose of
documenting the XML database.

My issue is that I have some fields, e.g.
<!ELEMENT Vehicle ( Car? )>
<!ELEMENT Car ( Gasoline | Diesel )>
<!ELEMENT Gasoline EMPTY>
<!ELEMENT Diesel EMPTY>

but I want to make sure that this database is extendable. I.e. after
using the database for a while in my application I want to be able to
add stuff that I come up with later on, e.g.
<!ELEMENT Motorcycle ( Sportbike | Harley )>
<!ELEMENT Sportbike EMPTY>
<!ELEMENT Harley EMPTY>

I'd rather not add a lot of "Reserved"-elements in the DTD, as this is
not a nice solution. My own little idea is that i'm anyway able to add
items to the DTD further on since I both have the DTD of the XML and
the source of the application using it. Is this correct?

I've looked around and found another way to do this and that is to
include the old DTD as an entity, is that the way to go?

Please excuse my newbie-question, I just want to know if my way of
thinking is correct.

Thanks a lot for reading!
 
G

George Bina

Hi Stefan,

I would recommend looking into using a schema language (XML Schema,
Relax NG) instead of a DTD.
With DTD probably the best approach is to use parameter entities to
define the content model for elements and the available attributes. You
can look at DocBook 4 for an example of using parameter entities. Note
that the next version of DocBook, DocBook 5 will provide a Relax NG
schema. More, it should be possible to convert from schema to DTD so if
you need to provide also a DTD then you will be able to do so. DocBook
5 for instance will provide also a DTD and an XML Schema.

Best Regards,
George
 
S

stefan.rickfjord

Hi George!

Thanks a lot for the reply, it is greatly appreciated and I will look
into this immediately!

With best regards, Stefan
 
P

Peter Flynn

Hi,

I am a newbie to programming using XML and I'm currently working on a
side-project which will house some database information in a XML-file.
I am writing a DTD to specify the XML-format, mostly for the purpose of
documenting the XML database.

My issue is that I have some fields, e.g.
<!ELEMENT Vehicle ( Car? )>
<!ELEMENT Car ( Gasoline | Diesel )>
<!ELEMENT Gasoline EMPTY>
<!ELEMENT Diesel EMPTY>

but I want to make sure that this database is extendable. I.e. after
using the database for a while in my application I want to be able to
add stuff that I come up with later on, e.g.
<!ELEMENT Motorcycle ( Sportbike | Harley )>
<!ELEMENT Sportbike EMPTY>
<!ELEMENT Harley EMPTY>

<!ENTITY % bikes SYSTEM "list.of.bikes">
....
<!ELEMENT Motorcycle EMPTY>
<!ATTLIST Motorcycle type (%bikes;) #REQUIRED>

where the file list.of.bikes contains something like

Sportbike|
Harley|
Triumph|
Yamaha

etc.

Now to keep the list up to date, you just have to edit list.of.bikes

///Peter
 

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,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top