Correct minor issues with doctype

Doctype methods were not comparing doctype objects as strings. This
caused a failure to detect when the doctype existed. Also, doctype was
having issues being added to the document in REXML on ruby 1.8.7.

This commit corrects the string comparison issues. It also takes a new
very cautious approach to adding the doctype to the document. This is
again to make up for shortcomings of the REXML library in ruby 1.8.7.