Is it possible to check if loaded with xmlDoc.loadXML(xmlData); xml string is invalid? For example if there is missed closing bracket or a tag.
Is it possible to check if loaded with xmlDoc.loadXML(xmlData); xml string is invalid? For
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you pass a string to
loadXMLthat isn’t a well-formed XML document, the document object will be empty (no childNodes) andxmlDoc.parseError.errorCodewill be set to something other than0.xmlDoc.parseError.reasonwill give you a user-readable error message.If you want to test a snippet and not a full document, wrap it in
<x>…</x>tags so that the parser will only see one root element.(There are a few reasons that MSXML might fail to parse a document other than it being non-well-formed. For example an external DTD subset or entity might not be network-reachable, or the DTD might use features MSXML doesn’t support. You can’t use MSXML to parse XHTML documents with their DTD for this reason. But if DTD-cruft isn’t involved, a parser failure means the input wasn’t well-formed.)