Segmentation fault with malformed XML

Malformed XML or even random input causes a segmentation fault. Added check for XML parser.