Add some nil checks for xmldom (and clean up a bit)

As Araq said in #1415:
> The proper fix is handle 'nil' for the attributes in the accessor rather than allocate memory like crazy.

Here's the proper fix.