Home
%3CLINGO-SUB%20id%3D%22lingo-sub-388301%22%20slang%3D%22en-US%22%3EValidate%20XML%20with%20rich%20error%20output%20in%20the%20XML%20Task%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-388301%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Mar%2004%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CDIV%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1708575259%22%20id%3D%22toc-hId-1731481566%22%3E%3C%2FH2%3E%3CBR%20%2F%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CP%3EValidate%20XML%20documents%20and%20get%20rich%20error%20output%20by%20enabling%20the%20%3CSTRONG%3E%20ValidationDetails%20%3C%2FSTRONG%3E%20property%20of%20the%20XML%20Task.%20For%20more%20info%2C%20see%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-US%2Flibrary%2Fmt684912(SQL.130).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Validate%20XML%20with%20the%20XML%20Task%20%3C%2FA%3E%20in%20the%20SSIS%20documentation.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESQL%20Server%26nbsp%3BIntegration%20Services%20(SSIS)%20introduced%20the%20%3CSTRONG%3E%20ValidationDetails%20%3C%2FSTRONG%3E%20property%20in%20SQL%20Server%202012%20Service%20Pack%202%20in%20July%20of%202014.%20This%20new%20property%20was%20not%20announced%20or%20documented%20at%20the%20time%20of%20its%20original%20release.%20The%20property%20is%20also%20available%20in%20SQL%20Server%202014%20and%20in%20SQL%20Server%202016.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20following%20screen%20shot%20shows%20the%20%3CSTRONG%3E%20XML%20Task%20Editor%20%3C%2FSTRONG%3E%20with%20the%20settings%20required%20for%20XML%20validation%20with%20rich%20error%20output.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F99935iC0B34E402D6685F0%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EBefore%20the%20%3CSTRONG%3E%20ValidationDetails%20%3C%2FSTRONG%3E%20property%20was%20available%2C%20XML%20validation%20by%20the%20XML%20Task%20returned%20only%20a%20true%20or%20false%20result%2C%20with%20no%20information%20about%20errors%20or%20their%20locations.%20Now%2C%20when%20you%20set%20%3CSTRONG%3E%20ValidationDetails%20%3C%2FSTRONG%3E%20to%20True%2C%20the%20output%20file%20contains%20detailed%20information%20about%20every%20error%20including%20the%20line%20number%20and%20the%20position.%20You%20can%20use%20this%20information%20to%20understand%2C%20locate%2C%20and%20fix%20errors%20in%20XML%20documents.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20XML%20validation%20functionality%20scales%20easily%20for%20large%20XML%20documents%20and%20large%20numbers%20of%20errors.%20Since%20the%20output%20file%20itself%20is%20in%20XML%20format%2C%20you%20can%20query%20and%20analyze%20the%20output.%20For%20example%2C%20if%20the%20output%20contains%20a%20large%20number%20of%20errors%2C%20you%20can%20group%20the%20errors%20by%20using%20a%20Transact-SQL%20query%2C%20as%20described%20in%20this%20topic.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--843581702%22%20id%3D%22toc-hId--820675395%22%3ESample%20output%20for%20XML%20that's%20valid%3C%2FH2%3E%3CBR%20%2F%3E%3CP%3EHere%20is%20a%20sample%20output%20file%20with%20validation%20results%20for%20a%20valid%20XML%20file.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%3C%2FSTRONG%3E%20%3CSTRONG%3E%20xml%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20version%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3D%221.0%22%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20encoding%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3D%22utf-8%22%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3F%26gt%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3CROOT%20ns%3D%22%26quot%3B%26lt%3BA%22%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fxmltools%2F2002%2Fxmlvalidation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fxmltools%2F2002%2Fxmlvalidation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fxmltools%2F2002%2Fxmlvalidation%3C%2FA%3E%22%26gt%3B%20%3C%2FROOT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%26lt%3Bmetadata%26gt%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CRESULT%3Etrue%3C%2FRESULT%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CERRORS%3E0%3C%2FERRORS%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CWARNINGS%3E0%3C%2FWARNINGS%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CSTARTTIME%3E2015-05-28T10%3A27%3A22.087%3C%2FSTARTTIME%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%3CENDTIME%3E2015-05-28T10%3A29%3A07.00%20%3C%2FENDTIME%3E%3C%2FSTRONG%3E%20%3CSTRONG%3E%207%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CXMLFILE%3Ed%3A%5CTemp%5CTestData.xml%3C%2FXMLFILE%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CXSDFILE%3Ed%3A%5CTemp%5CTestSchema.xsd%3C%2FXSDFILE%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CMESSAGES%3E%3C%2FMESSAGES%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-899228633%22%20id%3D%22toc-hId-922134940%22%3ESample%20output%20for%20XML%20that's%20not%20valid%3C%2FH2%3E%3CBR%20%2F%3E%3CP%3EHere%20is%20a%20sample%20output%20file%20with%20validation%20results%20for%20an%20XML%20file%20that%20contains%20a%20small%20number%20of%20errors.%20The%20text%20of%20the%20%3CERROR%3E%20elements%20has%20been%20wrapped%20for%20readability.%3C%2FERROR%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%3CROOT%20ns%3D%22%26quot%3Bhttp%22%3E%3C%2FROOT%3E%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3A%2F%2Fschemas.microsoft.com%2Fxmltools%2F2002%2Fxmlvalidation%22%26gt%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%26lt%3Bmetadata%26gt%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CRESULT%3Efalse%3C%2FRESULT%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CERRORS%3E2%3C%2FERRORS%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CWARNINGS%3E0%3C%2FWARNINGS%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CSTARTTIME%3E2015-05-28T10%3A45%3A09.538%3C%2FSTARTTIME%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CENDTIME%3E2015-05-28T10%3A45%3A09.558%3C%2FENDTIME%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%3CXMLFILE%3EC%3A%5CTemp%5CTestD%20%3C%2FXMLFILE%3E%3C%2FSTRONG%3E%20%3CSTRONG%3E%20ata.xml%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CXSDFILE%3EC%3A%5CTemp%5CTestSchema.xsd%3C%2FXSDFILE%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CMESSAGES%3E%20%3C%2FMESSAGES%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CERROR%20line%3D%22%26quot%3B5%26quot%3B%22%20position%3D%22%26quot%3B26%26quot%3B%22%3EThe%20'ApplicantRole'%20element%20is%20invalid%20-%20The%20value%20'wer3'%20is%20invalid%20%3C%2FERROR%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3Eaccording%20to%20its%20datatype%20'ApplicantRoleType'%20-%20The%20Enumeration%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20constraint%20failed.%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%3CERROR%20line%3D%22%26quot%3B16%26quot%3B%22%20position%3D%22%26quot%3B28%26quot%3B%22%3EThe%20'Phone'%20element%20is%20invalid%20-%20The%20value%20'we3056666666'%20is%20invalid%20%3C%2FERROR%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20according%20to%20its%20datatype%20'phone'%20-%20The%20Pattern%20constraint%20failed.%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId--1652928328%22%20id%3D%22toc-hId--1630022021%22%3EAnalyze%20XML%20validation%20output%20with%20a%20Transact-SQL%20query%3C%2FH2%3E%3CBR%20%2F%3E%3CP%3EIf%20the%20output%20of%20XML%20validation%20contains%20a%20large%20number%20of%20errors%2C%20you%20can%20use%20a%20Transact-SQL%20query%20to%20load%20the%20output%20in%20SQL%20Server%20Management%20Studio.%20Then%20you%20can%20analyze%20the%20error%20list%20with%20all%20the%20capabilities%20of%20the%20T-SQL%20language%20including%20WHERE%2C%20GROUP%20BY%2C%20ORDER%20BY%2C%20JOIN%2C%20and%20so%20forth.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20DECLARE%20%40xml%20XML%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20SELECT%20%40xml%20%3D%20XmlDoc%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20FROM%20OPENROWSET%20(BULK%20N'C%3A%5CTemp%5CXMLValidation_2016-02-212T10-41-00.xml'%2C%20SINGLE_BLOB)%20AS%20Tab(XmlDoc)%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20--%20Query%20%23%201%2C%20flat%20list%20of%20errors%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E--%20co%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20nvert%20to%20relational%2Frectangular%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%3BWITH%20XMLNAMESPACES%20('%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fxmltools%2F2002%2Fxmlvalidation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fxmltools%2F2002%2Fxmlvalidation%3C%2FA%3E'%20AS%20ns)%2C%20rs%20AS%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20(%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20SELECT%20col.value('%40line'%2C'INT')%20AS%20line%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%2C%20col.value('%40position'%2C'INT')%20AS%20position%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%2C%20col.value('.'%2C'VARCHAR(1024)')%20AS%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20error%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20FROM%20%40XML.nodes('%2Froot%2Fmessages%2Ferror')%20AS%20tab(col)%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20)%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20SELECT%20*%20FROM%20rs%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20--%20WHERE%20error%20LIKE%20%E2%80%98%25whatever_string%25%E2%80%99%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20--%20Query%20%23%202%2C%20count%20of%20errors%20grouped%20by%20the%20error%20message%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20--%20convert%20to%20relational%2Frectangular%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%3BWITH%20XMLNAMESPACES%20('%3CA%20href%3D%22http%3A%2F%2Fschemas.mi%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.mi%3C%2FA%3E%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20crosoft.com%2Fxmltools%2F2002%2Fxmlvalidation'%20AS%20ns)%2C%20rs%20AS%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20(%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20SELECT%20col.value('%40line'%2C'INT')%20AS%20line%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%2C%20col.value('%40position'%2C'INT')%20AS%20position%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20%2C%20col.value('.'%2C'VARCHAR(1024)')%20AS%20error%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20FROM%20%40XML.nodes('%2Froot%2Fmessages%2Ferror')%20AS%20tab(col)%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20)%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3ESELECT%20%3C%2FSTRONG%3E%20%3CSTRONG%3E%20COALESCE(error%2C'Total%20%23%20of%20errors%3A')%20AS%20%5Berror%5D%2C%20COUNT(*)%20AS%20%5Bcounter%5D%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20FROM%20rs%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20GROUP%20BY%20GROUPING%20SETS%20((error)%2C%20())%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3E%20ORDER%20BY%202%20DESC%2C%20COALESCE(error%2C%20'Z')%3B%20%3C%2FSTRONG%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EHere%20is%20the%20result%20in%20Management%20Studio%20of%20the%20second%20sample%20query%20shown%20in%20the%20preceding%20text.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F99936i504582294E4E6028%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-89882007%22%20id%3D%22toc-hId-112788314%22%3ESee%20Also%3C%2FH2%3E%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms141055.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20XML%20Task%20%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms188474.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20XML%20Task%20Editor%20%3C%2FA%3E%3C%2FP%3E%0A%20%0A%3CLINGO-TEASER%20id%3D%22lingo-teaser-388301%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Mar%2004%2C%202016%20%26nbsp%3BValidate%20XML%20documents%20and%20get%20rich%20error%20output%20by%20enabling%20the%20ValidationDetails%20property%20of%20the%20XML%20Task.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-388301%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eerror%20output%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Essis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Evalidate%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EXML%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Not applicable
First published on MSDN on Mar 04, 2016



Validate XML documents and get rich error output by enabling the ValidationDetails property of the XML Task. For more info, see Validate XML with the XML Task in the SSIS documentation.


SQL Server Integration Services (SSIS) introduced the ValidationDetails property in SQL Server 2012 Service Pack 2 in July of 2014. This new property was not announced or documented at the time of its original release. The property is also available in SQL Server 2014 and in SQL Server 2016.


The following screen shot shows the XML Task Editor with the settings required for XML validation with rich error output.



Before the ValidationDetails property was available, XML validation by the XML Task returned only a true or false result, with no information about errors or their locations. Now, when you set ValidationDetails to True, the output file contains detailed information about every error including the line number and the position. You can use this information to understand, locate, and fix errors in XML documents.


The XML validation functionality scales easily for large XML documents and large numbers of errors. Since the output file itself is in XML format, you can query and analyze the output. For example, if the output contains a large number of errors, you can group the errors by using a Transact-SQL query, as described in this topic.




Sample output for XML that's valid


Here is a sample output file with validation results for a valid XML file.


<? xml version ="1.0" encoding ="utf-8" ?>


<root xmlns:ns="http://schemas.microsoft.com/xmltools/2002/xmlvalidation">


<metadata>


<result>true</result>


<errors>0</errors>


<warnings>0</warnings>


<startTime>2015-05-28T10:27:22.087</startTime>


<endTime>2015-05-28T10:29:07.00 7</endTime>


<xmlFile>d:\Temp\TestData.xml</xmlFile>


<xsdFile>d:\Temp\TestSchema.xsd</xsdFile>


</metadata>


<messages />


</root>


Sample output for XML that's not valid


Here is a sample output file with validation results for an XML file that contains a small number of errors. The text of the <error> elements has been wrapped for readability.



<?xml version="1.0" encoding="utf-8"?>


<root xmlns:ns="http ://schemas.microsoft.com/xmltools/2002/xmlvalidation">


<metadata>


<result>false</result>


<errors>2</errors>


<warnings>0</warnings>


<startTime>2015-05-28T10:45:09.538</startTime>


<endTime>2015-05-28T10:45:09.558</endTime>


<xmlFile>C:\Temp\TestD ata.xml</xmlFile>


<xsdFile>C:\Temp\TestSchema.xsd</xsdFile>


</metadata>


<messages>


<error line="5" position="26">The 'ApplicantRole' element is invalid - The value 'wer3' is invalid


according to its datatype 'ApplicantRoleType' - The Enumeration constraint failed.</error>


<error line="16" position="28">The 'Phone' element is invalid - The value 'we3056666666' is invalid


according to its datatype 'phone' - The Pattern constraint failed.</error>


</messages>


</root>


Analyze XML validation output with a Transact-SQL query


If the output of XML validation contains a large number of errors, you can use a Transact-SQL query to load the output in SQL Server Management Studio. Then you can analyze the error list with all the capabilities of the T-SQL language including WHERE, GROUP BY, ORDER BY, JOIN, and so forth.


DECLARE @xml XML;



SELECT @xml = XmlDoc


FROM OPENROWSET (BULK N'C:\Temp\XMLValidation_2016-02-212T10-41-00.xml', SINGLE_BLOB) AS Tab(XmlDoc);



-- Query # 1, flat list of errors


-- co nvert to relational/rectangular


;WITH XMLNAMESPACES ('http://schemas.microsoft.com/xmltools/2002/xmlvalidation' AS ns), rs AS


(


SELECT col.value('@line','INT') AS line


, col.value('@position','INT') AS position


, col.value('.','VARCHAR(1024)') AS error


FROM @XML.nodes('/root/messages/error') AS tab(col)


)


SELECT * FROM rs;


-- WHERE error LIKE ‘%whatever_string%’




-- Query # 2, count of errors grouped by the error message


-- convert to relational/rectangular


;WITH XMLNAMESPACES ('http://schemas.mi crosoft.com/xmltools/2002/xmlvalidation' AS ns), rs AS


(


SELECT col.value('@line','INT') AS line


, col.value('@position','INT') AS position


, col.value('.','VARCHAR(1024)') AS error


FROM @XML.nodes('/root/messages/error') AS tab(col)


)


SELECT COALESCE(error,'Total # of errors:') AS [error], COUNT(*) AS [counter]


FROM rs


GROUP BY GROUPING SETS ((error), ())


ORDER BY 2 DESC, COALESCE(error, 'Z');



Here is the result in Management Studio of the second sample query shown in the preceding text.



See Also


XML Task


XML Task Editor