DTDs and syntax

J

JimO

If DTDs are supposed to enforce syntax rules, then why if I have the
following DTD the html underneath works?


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

<b><i>italics bold</b></i>
<img src="images/bacon.jpg">

The first line should be
<b><i>italics bold</i></b>
The second line should be
<img src="images/bacon.jpg" />

Shouldn't I get an error message or the code just won't work?
 
D

David Håsäther

JimO said:
If DTDs are supposed to enforce syntax rules, then why if I have the
following DTD the html underneath works?


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

<b><i>italics bold</b></i>
<img src="images/bacon.jpg">

Works? Where?

If you mean that it works your favorite browser, that's because it
doesn't handle DOCTYPE declarations (the way it's supposed to).
 
M

Michael Winter

If DTDs are supposed to enforce syntax rules,

The language - XML in this case - specifies the syntax rules. The DTD
defines what elements are permitted in the document, and how they should
(or should not) be used to structure the document. Neither enforce any
rules.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<b><i>italics bold</b></i>
<img src="images/bacon.jpg">
[snip]

Shouldn't I get an error message or the code just won't work?

If you're serving this as application/xhtml+xml and the user agent is a
'conforming user agent' (in the specification sense), then as I
understand it, the software should flag that as syntax error and stop
parsing. If it's also a validating parser (and it gets far enough into
the document), it should notify you that the markup is invalid.

If those conditions aren't true, the actions taken by a user agent are
implementation dependent.

Mike
 
J

Jukka K. Korpela

JimO said:
If DTDs are supposed to enforce syntax rules, then why if I have the
following DTD the html underneath works?

You seem to be throwing your question into more or less randomly chosen
newsgroups - I just answered it in alt.html.dhtml. Apparently you don't
want to get useful answers. Probably you should read a primer on HTML
before proceeding further. Oh, and please do not fix your forged From
field before you have a clue.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top