and do with it? I thought that in XML you can have a tag with opening and closing tags, and then if you don't need a c...">

Why can't I say <iframe / "> and do with it?

I thought that in XML you can have a tag with opening and closing tags, and then if you don't need a closing tag, you can just use a tag with a slash at the end of it.

<!-- needs text/elements within tag so opening and closing tag are needed --> <myTag>Text here</myTag> <!-- doesn't need text/elements so doesn't have closing tag --> <myTag /> 

I guess this is only because everything that everyone decided was the best, and now it's just a feature of XHTML, but why? Is there a technical reason for this that I don't know about?

Thanks!

+6
source share
3 answers

This is because XHTML DTD says so :)

Only these elements can be empty:

  • region
  • base
  • br
  • color
  • h
  • IMG
  • entrance
  • link
  • meta
  • couples

For example, link declared as:

 <!ELEMENT link EMPTY> 

whereas script and iframe are declared as:

 <!ELEMENT script (#PCDATA)> 

and

 <!ELEMENT iframe %Flow;> <!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*"> ... 
+7
source

If browsers treated XHTML as XML, you would be right. But they see it as HTML, where the rules are different.

+1
source

These are just HTML rules. Some elements, such as script and iframe tags, always have an end tag.

This is a bit of a fad since it contradicts the way XML works, where a self-closing tag is exactly the same as an empty tag.

0
source

Source: https://habr.com/ru/post/899797/


All Articles