XMLTransformer: Eliminate code duplication

Move XML Document parsing code to a function.
The function is not private so unit tests can use it.