XMLBuilder: encode "value" of xml tags

Add some tests and encode entities in the "value" string.

Apparently DOMDocument tries to parse the "value" of tags before trying
to encode it (doesn't make sense). It was failing on values like "&am"
and "&lt" with an "unterminated entity reference" error.