CodexArcanum
CodexArcanum

Reputation: 4016

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!"

Upvotes: 0

Views: 34

Answers (3)

Michael Kay
Michael Kay

Reputation: 163458

It's not allowed in HTML or XML. For a survey of approaches to handling non-hierarchic markup, the Wikipedia article is a good place to start:

https://en.wikipedia.org/wiki/Overlapping_markup

Upvotes: 2

Guffa
Guffa

Reputation: 700552

Overlapping tags like that is only possible as long as it's only tags in a text. As soon as the text is parsed into elements (HTML or XML), it's not possible to represent such a structure.

The concept of an elements is that it is a single entity, it's not a starting and ending point in a text.

As your SO markdown example shows, it's possible to use tags like that as long as it's just tags in a text. As Quentin showed, the SO text parser has to translate that into a non-overlapping structure to be able to create valid HTML code for it.

Upvotes: 1

Quentin
Quentin

Reputation: 943935

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>

Upvotes: 1

Related Questions