Search code examples
htmlxmlsgml

Are there valid cases in HTML/XML where tags would not be fully contained?


I think in XML and HTML that having cross-scoped tags is not allowed. Maybe SGML allows it. In XML/HTML though, are there any valid and allowed cases where this can occur?

Something like:

<p>This is <i>some <b>example</i> text</b> right here!</p>

Which would likely generate output like: "This is some example text right here!"

(Sidenote: the SO markdown parser apparently can handle it, who knew?)

"This is *some **example* text** right here!"

Solution

  • I think in XML and HTML that having cross-scoped tags is not allowed.

    Correct

    Maybe SGML allows it.

    It doesn't.

    In XML/HTML though, are there any valid and allowed cases where this can occur?

    No. The markup just describes a DOM which is a tree of nodes. A node can only have one parent.

    "This is some example text right here!"

    That is rendered as:

    <p>"This is <em>some <strong>example</strong></em><strong> text</strong> right here!"</p>