halfway implementation of toXML