Re: Weird validation result



X Ryl wrote:
Hi,

I've tried validate something like (declaration excluded) :
<h1>foo <div>bar</div></h1>

It doesn't validate, as <h1>'s DTD is : <!ELEMENT (%heading;) - -
(%inline;)* -- heading -->
meaning that h1 can only contains inline element.

That's strange as DIV DTD is : <!ELEMENT DIV - - (%flow;)*
-- generic language/style container -->
with flow being "block or inline"

Right, but that's irrelevant to what's happening with your code.


That's also strange as the same code with p in-place of h1 validate:
<p>foo <div>bar</div></p>
and P DTD ( <!ELEMENT P - O (%inline;)* -- paragraph --> )
is declared like H1

The difference is that H1 has "- -" and P has "- O". The end tag is optional for P, which means that the user agent closes the P element automatically as soon as it encounters the beginning of another element that can't be nested inside or the end of an element within which the P element is nested. In your example, the validator deems the P to be closed as soon as it encounters the start tag for the DIV, and it interprets the two elements as a P element *followed by* a DIV element, not as a P element *containing* a DIV element. However, the validator will also flag the closing </p> as an error because no P element is open at that point. Did you notice that?

The H1 end tag isn't optional, and since you haven't explicitly closed the H1 element at the point where the DIV begins, the validator treats your code is nesting a DIV inside the H1, which isn't allowed.


Also, both P and H1 are declared in block level elements.

This has no bearing on what they can or can't contain.
.



Relevant Pages

  • Re: Massive HTML coding errors
    ... that a validator wouldn't comment on, ... The DTD at the top of your HTML code is invalid! ... those for your images, and a width of, say, 50% for the div that starts ... You need to be more careful when defining "font-family". ...
    (comp.infosystems.www.authoring.html)
  • Re: Massive HTML coding errors
    ... that a validator wouldn't comment on, ... The DTD at the top of your HTML code is invalid! ... those for your images, and a width of, say, 50% for the div that starts ... You need to be more careful when defining "font-family". ...
    (comp.infosystems.www.authoring.html)
  • Re:
    /IE problem...

    ... "fluid" design I have not given the sidenav div a fixed width.. ... as for the CSS, I just checked above url in W3C CSS validator, it validates.. ... you are running this in quirksmode when you don't have a strict doctype with a path. ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: some validation errors f
    ... an html element and a head element to be "opened". ... The validator will flag an error. ... have a div here, as you have been told a few times before. ... able to use ajax to repace the "content" of that div, ...
    (comp.infosystems.www.authoring.html)
  • Re: Problem with code in Firefox, works OK in Netscape 7.1
    ... Since you appear to be fairly new to Usenet, you should know that it is ... `script' element CDATA content and regard the rest as not Valid. ... Validator does show this as an error in the markup. ... Elements are represented by start tag and corresponding end tag, ...
    (comp.lang.javascript)