SGML

Tag Inference Examples

tag-minimization/test2

Basic omission of the start- and end-element tags for element a, as allowed by the O O tag omission indicators; as shown in the result, the missing tags are generated by SGML

tag-minimization/test6a
Shows that SGML will infer more than a single start-tag
tag-minimization/test7a

Variant of test6a where an addtional element f may be placed before b in e; this doesn't affect the inference of b and its containing elements

tag-minimization/omittag-pcdata1 tag-minimization/omittag-pcdata2 tag-minimization/omittag-pcdata3

Examples showing that parsed character data can also trigger tag inference; moreover, these examples show special processing of whitespace, followed by non-whitespace character data in content: handling of whitespace (including newline and tab characters) depends on whether PCDATA is accepted in the current context position without tag inference; if it is, then leading whitespace is considered part of parsed character data; otherwise, state transitions (including actions such as closing finished or opening required elements) are driven only with the portion starting PCDATA, any leading whitespace belonging to a separately reported characters event is ignored for validation

tag-minimization/rank-implied-element0 tag-minimization/rank-implied-element3

Examples for rank-based tag inference where generation of Sn elements around sequence of Hn/Pn is desired

Note: To process SGML from the example sources, copy and paste an example source, store it into a file with the ".sgm" file extension, and invoke
sgmlproc <your-file.sgm>
where <your-file.sgm> is replaced by the actual file used for storing.

tag-minimization/test2

<!DOCTYPE test [
	<!ELEMENT test - - (a, b)>
	<!ELEMENT a O O (a1,a2)>
	<!ELEMENT a1 - - (#PCDATA)>
	<!ELEMENT a2 - - (#PCDATA)>
	<!ELEMENT b - - (#PCDATA)>
]>
<test><a1>bla</a1><a2>fasel</a2><b>fasel</b></test>

tag-minimization/test6a

<!DOCTYPE a [
	<!ELEMENT a O - (b?, c) >
	<!ELEMENT b - - CDATA >
	<!ELEMENT c O - (d) >
	<!ELEMENT d O O (e) >
	<!ELEMENT e O O (b?) >
]>
<a><c><b>element b</b></c></a>

tag-minimization/test7a

<!DOCTYPE a [
	<!ELEMENT a O - (b?, c) >
	<!ELEMENT b - - CDATA >
	<!ELEMENT c O - (d) >
	<!ELEMENT d O O (e) >
	<!ELEMENT e O O (f?, b?) >
	<!ELEMENT f O O CDATA >
]>
<a><c><b>element b</b></c></a>

tag-minimization/omittag-pcdata1

<!DOCTYPE test [
	<!ELEMENT test - - (title, text)>
	<!ELEMENT title O O (#PCDATA)>
	<!ELEMENT text - - (#PCDATA)>
]>
<test>
<title>Bla bla</title>
<text>fasel</text>
</test>

tag-minimization/omittag-pcdata2

<!DOCTYPE test [
	<!ELEMENT test - - (title, text)>
	<!ELEMENT title O O (#PCDATA)>
	<!ELEMENT text - - (#PCDATA)>
]>
<test>Bla bla
<text>fasel</text>
</test>

tag-minimization/omittag-pcdata3

<!DOCTYPE test [
	<!ELEMENT test - - (b, c)>
	<!ELEMENT b - O (a, #PCDATA)>
	<!ELEMENT a - - (#PCDATA)>
	<!ELEMENT c - - (#PCDATA)>
]>
<!-- tests that content model ending with PCDATA (always optional) gets
     closed when infering omitted tags -->
<test>
<b><a>bla</a><c>fasel</c>
</test>

tag-minimization/rank-implied-element0

<!DOCTYPE TEST [
	<!ELEMENT TEST - - (S1+)>
	<!ELEMENT S 1 O O (H1,P1,S2*)>
	<!ELEMENT S 2 O O (H2,P2)>
	<!ELEMENT (H|P) 1 - - (#PCDATA)>
	<!ELEMENT (H|P) 2 - - (#PCDATA)>
]>
<TEST>
<H1>h2.1</H1>
<P1>p2.1</P1>
<H2>h2.2</H2>
<P2>p2.2</P2>
</TEST>

tag-minimization/rank-implied-element3

<!DOCTYPE TEST [
	<!ELEMENT TEST - - (S1+)>
	<!ELEMENT S 1 O O (H1,P1,S2*)>
	<!ELEMENT S 2 O O (H2,P2)>
	<!ELEMENT (H|P) 1 - - (#PCDATA)>
	<!ELEMENT (H|P) 2 - - (#PCDATA)>
]>
<TEST>
<H1>h1.1</H1>
<P1>p1.1</P1>
<H2>h2.1.1</H2>
<P2>p2.1.2</P2>
<H1>h1.2</H1>
<P1>p1.2</P1>
<H2>h2.2.2</H2>
<P2>h2.2.3</P2>
</TEST>