Check XML to see if well-formed
Posted on 2007-11-27
Is there a way to check if a string containing XML contains well-formed XML? I do not have, nor do I want an XSD. Also, It is not an XML file, but rather an XML stub.
What I am doing is writing a function that will insert data into a SQL Server table. One of the table's fields is of type xml. If I do an insert and the xml field does not contain well-formed xml, then the insert throws an exception. I'd like to catch this before I do the insert.
Also, note that I will have no control over how the XML string may be formed prior to it being passed to me.