Great article! What if there were multiple errors when validating the XML document and I wanted to store the error code, attribute and value in a table so I can create an error report?
Hi Suhail, You can put your code into a TRY CATCH block and capture the ERROR_MESSAGE() which can then be inserted to a log table.
For example:
BEGIN TRY DECLARE @x XML(PersonSchema) SELECT @x = ' [Person] [PersonType]SC[/PersonType] [/Person]' END TRY BEGIN CATCH SELECT ERROR_MESSAGE() END CATCH
Great article! What if there were multiple errors when validating the XML document and I wanted to store the error code, attribute and value in a table so I can create an error report?
ReplyDeleteHi Suhail,
ReplyDeleteYou can put your code into a TRY CATCH block and capture the ERROR_MESSAGE() which can then be inserted to a log table.
For example:
BEGIN TRY
DECLARE @x XML(PersonSchema)
SELECT @x = '
[Person]
[PersonType]SC[/PersonType]
[/Person]'
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE()
END CATCH
Note: Please replace [] with XML tags