Lesson 6: Validation of incorrect HTML


#1

I typed the following answer and submitted it:

<!DOCTYPE html>
<html>
	<head>
		<title>Nested lists</title>
	</head>
	<body>
		<ol>
			<li>Dad's interests
				<ul>
					<li>football</li>
					<li>knitting</li>
				</ul>
			</li>
			<li>Mom's interests
				<ul>
					<li>hating football</li>
					<li>skydiving</li>
				</ul>
			</li>
		</ol>
		<ul>
		    <li>Favorite Boy's names
		        <ol>
		            <li>Michael</li>
		            <li>Peter</li>
		            <li>John</li>
		        </ol>
		    </li>
		    <li>Favorite Girl's names
		        <ol>
		            <li>Anouk</li>
		            <li>Nuknuk</li>
		            <li>Nuki</li>
		        </ol>
		    </li
	    </ul>
	</body>

It got accepted. However, please note that I did not properly close the tag on the third line from the bottom.


#2

The validation of the code is done using regex, to cover ever corner case would require so many lines of code. So yea, a missing > will slip through


#3

Reminds me of the classic http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags. Is there no better way to do this without regex though? I mean, there are html-validators that catch the mistake (e.g. https://validator.w3.org/). I just don't know how they function and if they work without regex.


#4

Well, since this technology already exist, you can just test your code there. This validates if the syntax is correct, this is different from checking if the requirements of the exercise are met. The regex will catch most of the mistakes, if this needs to be implanted, it would mean so much additional load, for just a few cases