Fix issues with getting Xml as SimpleXmlElement and invalid Xml.

Fixes #3855