dom: Stop serialize from always reporting an error

The serialize function has an optional exception argument
to catch errors. One of our checks comes from normalising the
document and (at this point) this should only see namespace
errors. If not, we throw an internal error. However, the check
forgot that getException returns 0 if we are not in an exception
and turned the no exception case into an internal error. This is
fixed by checking if we are in an exceptional state before checking
the error code.
dom: Add simple tests for serialize

We don't check for error condition (e.g. in previous
commit) yet as it's not obvious how to trigger it
without first raising an error elsewhere when we
build our dom.