I've got pretty print much closer, but I haven't yet been able to produce it with a starting indent level. The alternative is to run the file xml output through the pretty printer before writing the file.
Small things are killing me..... some concatenation is wrapped in spaces, some isn't.... Some functions start braces on the 2nd line, some don't
I think this is the last one
I removed the string manipulation in favor of something more development friendly. The drawback is that the resulting XML is not as pretty, although I did run the processed fields through DOMDocument pretty printer. The entire resultant XML could be run through a pretty printer, but still won't achieve the tab indented node attributes.
The entire process could be made much more efficient, but this was just an initial conversion.