More robust XML parsing