The entities should end with a semicolon. Since you don’t have a semicolon after >, if you put the number right after it the browser interprets it as a three digit entity number. Bottom line, add semicolons to the end of your entities.
You don’t want to use xmp because it is technically no longer a valid tag in HTML5. A lot of browsers might support it right now, but it will eventually die off completely.
If you want to be semantically correct, use code. As far as formatting your code, use a JS library to help you do that. Or you could use the pre tag which will preserve the whitespace and returns.