Fix #544: Space after document causes validation error

 - ignore leading/trailing whitespace