PDA

View Full Version : Creating DTD's


sagat
02-06-2004, 05:47 PM
Hi all, i would like to create a DTD for some webpages and the corresponding XML schema and XSL. Any ideas? Thanks

me'
02-07-2004, 06:51 PM
DTDs at w3chools (http://www.w3schools.com/dtd/default.asp).

liorean
02-07-2004, 07:18 PM
Hmm, ZVON <http://www.zvon.org/> has a number of useful tutorials and references. <http://www.garshol.priv.no/download/xmltools/> has a load of tools.

sagat
02-09-2004, 09:39 PM
Thanks,
I have created a XML document and i would like to create the corresponding DTD's. Any ideas?

<?xml version="1.0"?>
<User>
<Student>StudentID</Student>
<Lecturer>LecturerID</Lecturer>
<Module>
<StudentModules>Student/Course/Module</StudentModules>
<StaffModules>Lecturer/course/Module</StaffModules>
<Course>Course/Module
<Assignment>Assignment Task</Assignment>
<Mark>Student/Course/Module/Mark</Mark>
</Course>
</Module>
</User

liorean
02-09-2004, 09:58 PM
You aren't describing in well enough for me to know exactly what you want, but here's a simple sample DTD (Just elements, no attributes or entities.)

<!ELEMENT User (Student | Lecturer | Module)+>
<!ELEMENT Student (#PCDATA)>
<!ELEMENT Lecturer (#PCDATA)>
<!ELEMENT Module (StudentModules | StaffModules | Course)+>
<!ELEMENT StudentModules (Student | Course | Module)+>
<!ELEMENT StaffModules (Lecturer | Course | Module)+>
<!ELEMENT Course (Assignement | Mark)>
<!ELEMENT Assignment (#PCDATA)>
<!ELEMENT Mark (Student | Course | Module | #PCDATA)>

sagat
02-10-2004, 12:11 PM
Thanks i was basing the XML on the diagram which is attached. Basically when a student or lecturer logs in they can look at thier module details and see marks etc. The diagram should explain it better. I hope the XML is right for the diagram.

sagat
02-10-2004, 10:39 PM
I tried creating the DTD and i kept getting errors.

<?xml version="1.0" encoding="UTF-8"?>

<!ELEMENT User (Student | Lecturer | Module)+>
<!ELEMENT Student (#PCDATA)>
<!ELEMENT Lecturer (#PCDATA)>
<!ELEMENT Module (StudentModules | StaffModules | Course)+>
<!ELEMENT StudentModules (Student | Course | Module)+>
<!ELEMENT StaffModules (Lecturer | Course | Module)+>
<!ELEMENT Course (Assignement | Mark)>
<!ELEMENT Assignment (#PCDATA)>
<!ELEMENT Mark (Student | Course | Module | %PCDATA>

<!ATTLIST Student CDATA %REQUIRED;>
<!ATTLIST Lecturer CDATA %IMPLIED;>
<!ATTLIST Student Modules CDATA #IMPLIED>
<!ATTLIST Staff Modules CDATA #IMPLIED>
<!ATTLIST Assignment Task CDATA #IMPLIED>

]>

Alex Vincent
02-11-2004, 05:37 PM
Would you please post it to a URL so I can look at it from Mozilla?

Tails
02-25-2004, 11:43 PM
I understand how to create a dtd, but how do I load it from the document? Here's an XHTML 1.0 Strict DTD

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!DOCTYPE> is the tag,

html and public are some valueless attributes which I have no idea what they are for (and xhtml doesn't let you use attributes without values, such as 'border').

The first thing in quotation marks:
"-//W3C//DTD XHTML 1.0 Strict//EN"
Maybe that's just a meaningless thing. Makes no sense to me.

And lastly:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
This is the one part that makes sense.


So to load my own doctype do I simply make an xml file such as


<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE "fiile.dtd">
<testdata>
<x value="Tails" />
</testdata>


and the dtd would contain


<!ELEMENT testdata (x?)>
<!ELEMENT x (#CDATA)>
<!ATTLIST x value CDATA "">


Is this correct? I know there are validators for the rules of XML (all tags must end, etc) but is there a way to validate an XML file according to it's doctype? How exactly are you supposed to load a dtd and what's the XHTML doctype attributes mean?

liorean
02-26-2004, 01:23 AM
Well, let's get on explaining. In XML there are three kinds of tags:
- Elements <elementname attributes>, which may be empty or containers.
- Parser Commands <!parsercommand> of multiple types, that have a special structure I will come back to.
- PIs (Processing Instructions) <?PI?> that you may use for telling the XML parser to call other external content processors.

Then there is a special case - the XML prolog - which despite it's looks is not a PI, nor it is any of the others.

The element structure you know. The XML prolog you know. Other PIs you probably have an idea about. The parser command structure may be new to you, however.



{Now, I'm not exactly sure which additional limits XML puts that SGML didn't put on these things, so I might be generalising too much for XML here. Anyway, I'll try to explain it without it ending in essay size...}

All in all, the parser command structure is a general groupd for very many constructs. Inside it you may have three general structures:
- A comment (in XML only a single one, though SGML allowed more than one), starting and ending with a double hyphen. <!-- E.g. this parser command containing a single comment -->
- A block structure, starting in left brace followed by a descriptor followed by another left brace, ending in two right braces. <![CDATA[ E.g. this parser command containing a single CDATA block ]]>
- If the parser command does not start in a comment or a container, the first part must be a descriptor, like DOCTYPE, ELEMENT, ATTLIST, ENTITY, or NOTATION. Each of these have it's own structure for the parts following.


The doctype follows this structure:
- DOCTYPE
- rootelement
- identifier (which may follow either of the following syntaces)
&nbsp;&nbsp;&nbsp;> PUBLIC officialname dtduri
&nbsp;&nbsp;&nbsp;> SYSTEM dtduri
- internal subset (a DTD or part of a DTD, enclosed with braces)

E.g <!DOCTYPE root PUBLIC "-//Source//Name and Version//Language" "http://example.net/example.dtd" [
&nbsp;&nbsp;&nbsp;<!-- A comment within the doctype -->
&nbsp;&nbsp;&nbsp;<!ELEMENT root EMPTY>
]>