Fix: Properly end XML parent element before adding XML fragment