XMLdocument.transform Question

I am builing an xml file.

The I want to store it prettystyled using the example from documentation as described under xmldocument.transform.

Before running the transform my xml contains a element as follows:

After tranformation is executed, the document element get corrupted as follows

How do I keep my original document element as is before the transform?

anyone?

OK I am patching the string after transformation has taken place, but I feel that is not the intention…