Indeed, I suggest that you find an "XML lint" tool and run it against the file, along with its schema if you have one (you should...) to see if it is, in fact, valid XML. If it is, then I cordially suggest that you may prefer to use a more rugged set of tools such as
XML::LibXML and its brethren ... which employs an industry-standard set of XML libraries to reliably do just about anything that you could possibly want to do with an XML file of any size. (Including, I might add, the use of "XPath expressions" ... the Swiss Army Knife of XML.)