I want to validate if a given html table syntax is correct, with respect to all colspan and rowspan definitions.
The following table is syntactically correct:
<table id="correct">
<tr>
<td>a</td>
<td>b</td>
<td rowspan="2">c</td>
</tr>
<tr>
<td colspan="2">d</td>
</tr>
</table>
The next table is wrong because both the columns and rows are not matching:
<table id="wrong1">
<tr>
<td>a</td>
<td>b</td>
<td rowspan="1">c</td>
</tr>
<tr>
<td colspan="1">d</td>
</tr>
</table>
I want to be able to validate if a table is correct or wrong. The given code is just an example, it should validate with any given table, regardless of its complexity.
I could begin to write my own validator, but before that i’d like to know if there are any libraries or already-working solutions out there. Can you help me on this?
/edit
Just found this online validator:
http://wet-boew.github.com/wet-boew/demos/tableparser/validator-htmltable.html
My first wrong table #wrong1 throws an error, but #wrong2 does not (see fiddle). Seems that it does not support too large numbers.
Based on the answer of Shehabix, i rewrote the validator. Main improvements:
DEMO
(see the developer console for output)
JavaScript
—