I've written a XML code to create tables. But, the problem is whenever I remove the nested tag from a specific block the table row alternates. SOURCE CODE
<?xml version="1.0" encoding="UTF-8">
<!DOCTYPE html PUBLIC "~//W3C//DTD XHTML 1.1/EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd">
<head>
<title>Test</title>
</head>
<body>
<table style="border-collapse=collapse" border="2">
<tr><td rowspan="20"><b>Department</b></td></tr>
<tr><tr><td rowspan="5">Sem1</td></tr>
<tr><td>sub1</td></tr>
<tr><td>sub2</td></tr>
<tr><td>sub3</td></tr></tr>
<tr><tr><td rowspan="5">Sem2</td></tr>
<tr><td>sub4</td></tr>
<tr><td>sub5</td></tr>
<tr><td>sub6</td></tr></tr>
<tr><tr><td rowspan="5">Sem3</td></tr>
<tr><td>sub7</td></tr>
<tr><td>sub8</td></tr>
<tr><td>sub9</td></tr></tr>
</table>
</body>
Any solutions?
OUTPUT correct output
But when i remove the i.e. the one outside, which encloses 4 lines of code.
<--!tr tag removed--> <tr><td rowspan="5">Sem2</td></tr>
<tr><td>sub4</td></tr>
<tr><td>sub5</td></tr>
<tr><td>sub6</td></tr> <--!tr tag removed-->
the output comes like this wrong output
Leaving out the issue of XHTML already addressed in comments, you probably want HTML code such as the following:
The effect you're observing with
rowspan=5is that when an HTML parser encounters a<tr>tag immediately followed by another<tr>tag, a</tr>end-element tag is inferred before the second<tr>start-element tag, and thus an empty table row in counted towards the rowspan value.To get an idea of how this behavior of HTML parsers (originally derived from SGML end-tag inference) works, consider the above corrected HTML code with
</tr>elements omitted:The latter is equivalent to the former according to the HTML specification which states that
And in fact, an SGML parser can infer those (provided
<DOCTYPE html>is changed to<!DOCTYPE html "about:legacy">to tell SGML the HTML parsing rules as explained in eg. https://sgmljs.net/docs/parsing-html-tutorial/parsing-html-tutorial.html; actually, even</td>end-elements can be omitted; this however isn't implemented in the built-inabout:legacy-compatHTML mini-DTD ofsgmlprocthough, so one needs to use the full HTML DTD).Now I would've loved to send you to W3C's nu HTML 5 validator to check your HTML but its results are confusing (check it our yourself), seemingly inferring additionaltbodystart-element tags, which isn't backed by the content model specification for thetableelement:meaning
tbodyis optional and not inferred as a wrapper aroundtrelements even though its start- and end-elements can be omitted. The latter is how the parsing rules are implemented in the HTML5x and the newer 2020 and 2023 HTML Review Draft DTDs at https://sgmljs.net/docs/html5.html. This ambiguity is also briefly discussed in the the HTML 5 DTD reference.See Alohci's comment regarding nu validator's inference of
tbodyelements.See also WHATWG's HTML specification for the referenced citations.