Various SimpleXML bugfixes.

Alright, let's try this again!

I've left out the commit that breaks the zend test. All commits below should include a test themselves.

Let me know if I need to change anything.