Speed up trivial-validate

This brings the time for trivial-validate from 17s to 7s on my machine.

Improvements: Precompile XPath queries and save the values of repeated queries. Precompile regexes. Read from sqlite instead of files to reduce number of filesystem operations.

Similar changes in make-sqlite.py bring it from 5.7 seconds to 3.7 seconds.