﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Jacob Sebastian / Article Discussions / Article Discussions by Author  / XML Workshop VII - Validating values with SCHEMA / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 17:54:50 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>Is there any way to get all error messages validating xml using xsd?no CLR or any dlls.</description><pubDate>Mon, 28 Jan 2013 11:56:15 GMT</pubDate><dc:creator>Milko González</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>hi, can any one please let me know how to get multiple error messages while validating xml using xsd?no CLR or any dlls.thank you so much in advance.</description><pubDate>Mon, 25 Jul 2011 08:32:11 GMT</pubDate><dc:creator>poorna.saikam</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>Here is an example that I just tried and it works[code]DECLARE @x XML(CustomerSchema), @y XMLSELECT @y = '&lt;test&gt;a&lt;/test&gt;'BEGIN TRY	SELECT @x = @yEND TRYBEGIN CATCH	RAISERROR('Hey, this is an invalid XML',16,1)END CATCH/*OUTPUT:Msg 50000, Level 16, State 1, Line 7Hey, this is an invalid XML*/[/code]</description><pubDate>Tue, 05 May 2009 01:41:26 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>Hi Jacob,I am trying to Raise an error using RAISEERROR function in sql when the XML schema validation fails.I am doing this inside a store proc. I am declaring the XML doc binding it to it's XSD schema in the TRY block and if validation fails, raise a user define error number by using RAISEERROR function in the catch block. However, somehow i am not able to do this and sql return it's own error the moment it executes that line of code. So using Employee example here, I am doing something like this.CREATE PROC ImportEmployeeInfo@EmployeeXML as XMLASBEGINBEGIN TRYDECLARE @EmpXML AS XML(EmployeeSchema) --declaring a local XML variable and binding it to a schemaDECLARE @LocalErrorSET @EmpXML = @EmployeeXML -- here I am setting the @EmpXML to @EmployeeXML variable passed inIF @@error&amp;lt;&amp;gt;0 --if the @EmployeeXML failed the XSD validation, i beileve there would be an error rightBEGIN       SET @LocalError = 50001 --user defined error       RaiseError(' The input parameter @EmployeeXML is not valid', 16, 1)END--The XML shredding and import into table goes hereEND TRYBEGIN CATCH--I have another another user defined errorhandler proc here which will take the above @LocalError --as input parameter and raise a detailed errorEND CATCHEND --End of Proc</description><pubDate>Thu, 02 Apr 2009 22:02:07 GMT</pubDate><dc:creator>bdba</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>The regular expression language is documented here: http://www.w3.org/TR/xmlschema-2/#regexsThe documentation is not very easy to understand but you might be able to spot the problem with your syntax.I have included a detailed RegularExpression tutorial in my XSD book which will be out in a few days. Keep a watch at http://www.sqlservercentral.com/articles/books/65843/</description><pubDate>Sat, 28 Mar 2009 11:54:53 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>great thanks for the info.  i have another problem.  i'm trying to use a xsd validation again with regular expression, i got the regex from regexlib and it's great when i'm testing the xml using xsd validation tool. but when i try to create xsd collection in sql i got an error.[code]Msg 102, Level 15, State 1, Line 32Incorrect syntax near 'year'.[/code]xsd collection attached</description><pubDate>Sat, 28 Mar 2009 02:34:29 GMT</pubDate><dc:creator>tengtium</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>XML data type can store XML DOCUMENTS  (having exactly 1 root element) and XML CONTENT (having 0 or more top level elements). The default is CONTENT and hence it allows 0 or more top level elements. The schema performs a validation only if the element is present.Declare your XML variable as DOCUMENT and then SQL Sever will perform the validation that you expect. For example:[code]DECLARE @x XML(DOCUMENT EmployeeSchema)[/code]</description><pubDate>Mon, 09 Mar 2009 13:04:24 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>using the article example.this is empty xml (assuming it's the content of the file is coming from outside, meaning the content was read in an .xml file[code] DECLARE @emp AS XML(EmployeeSchema)   SET @emp = ''[/code]this is empty xml (assuming it's the content of the file is coming from outside, meaning the content was read in an .xml file[code] DECLARE @emp AS XML(EmployeeSchema)   SET @emp = 'put a valid xml comment here'[/code]why to two last statement is valid??? why an empty xml or an xml with valid xml comment cannot be validated by predefined schema.is there a way to validated an empty xml or an xml file which is the only content is a valid xml comments?please help.</description><pubDate>Sat, 07 Mar 2009 22:12:13 GMT</pubDate><dc:creator>tengtium</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>&lt;P&gt;Hi Herit,&lt;/P&gt;&lt;P&gt;There is an article in this series which explains the enumeration in detail.&lt;/P&gt;&lt;P&gt;I am not sure what is the scheduled date. But I guess it will be out in a week.&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Jacob&lt;/P&gt;</description><pubDate>Wed, 19 Sep 2007 23:57:00 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>Do you have any idea why there is a requirement for timezone on date and time fields?According to W3C timezone is optional on date, time and datetime fields.http://www.w3.org/TR/xmlschema-2/#dateTime/Micke</description><pubDate>Wed, 19 Sep 2007 23:41:00 GMT</pubDate><dc:creator>Mikael Eriksson SE</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>&lt;P&gt;Hello Jacob,&lt;/P&gt;&lt;P&gt;You gave really useful information in easy way with example. Can you post the way to deal with Enumeration (for example weekdays Sunday, Monday,... Saturday) in XML Schema validation? &lt;/P&gt;&lt;P&gt;Thank you once again for your articles.&lt;/P&gt;</description><pubDate>Wed, 19 Sep 2007 17:36:00 GMT</pubDate><dc:creator>Harit Gohel</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>&lt;P&gt;dinesh,&lt;/P&gt;&lt;P&gt;I did not notice your message until this morning (when i get into this page accidently), because this article is not yet published. It is scheduled and will be out soon.&lt;/P&gt;&lt;P&gt;You need to apply an 'XQuery' conversion before the value can be converted to a valid SQL Server datetime value. Use the function "xs:dateTime()" or "xs:date()" for the conversion. Here is an example.&lt;/P&gt;&lt;FONT color=#0000ff&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;DECLARE&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; @emp &lt;FONT color=#0000ff&gt;AS&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;XML&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;SET&lt;/FONT&gt; @emp &lt;FONT color=#808080&gt;=&lt;/FONT&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT face="Courier New"&gt;'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;Employee EmployeeNumber="1001" Language="EN" &amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;FullName&amp;gt;Jacob&amp;lt;/FullName&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;Salary&amp;gt;10000&amp;lt;/Salary&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;Age&amp;gt;30&amp;lt;/Age&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;Married&amp;gt;1&amp;lt;/Married&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;BirthDate&amp;gt;1975-03-14T12:00:00+05:30&amp;lt;/BirthDate&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;ReportingTime /&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;/Employee&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;'&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SELECT&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;x&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;e&lt;FONT color=#808080&gt;.&lt;/FONT&gt;value&lt;FONT color=#808080&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;'@EmployeeNumber[1]'&lt;/FONT&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;'varchar(20)'&lt;/FONT&gt;&lt;FONT color=#808080&gt;)&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;as&lt;/FONT&gt; EmpNumber&lt;FONT color=#808080&gt;,&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;x&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;e&lt;FONT color=#808080&gt;.&lt;/FONT&gt;value&lt;FONT color=#808080&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;'FullName[1]'&lt;/FONT&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;'varchar(40)'&lt;/FONT&gt;&lt;FONT color=#808080&gt;)&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;as&lt;/FONT&gt; FullName&lt;FONT color=#808080&gt;,&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;x&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;e&lt;FONT color=#808080&gt;.&lt;/FONT&gt;value&lt;FONT color=#808080&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;'xs:dateTime(BirthDate[1])'&lt;/FONT&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;'datetime'&lt;/FONT&gt;&lt;FONT color=#808080&gt;)&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;as&lt;/FONT&gt; BirthDate&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size=7&gt;&lt;FONT size=1&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;@emp&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;nodes&lt;FONT color=#808080&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;'Employee'&lt;/FONT&gt;&lt;FONT color=#808080&gt;)&lt;/FONT&gt; x&lt;FONT color=#808080&gt;(&lt;/FONT&gt;e&lt;FONT color=#808080&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Wed, 08 Aug 2007 04:33:00 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item><item><title>RE: XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>&lt;P&gt;In the article you had written that we need to give time zone information while creating xml for a date or time field. In this case when we use xpath query to get the value of a date field via following query I am getting a error message.&lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;   &lt;/SPAN&gt;x.item.value(&lt;SPAN style="COLOR: #a31515"&gt;'Employee\@ReportingTime[1]'&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;'Datetime'&lt;/SPAN&gt;) &lt;SPAN style="COLOR: blue"&gt;AS &lt;/SPAN&gt;&lt;FONT color=#111111&gt;ReportingTime&lt;/FONT&gt;&lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt; &lt;FONT color=#111111&gt;  Let say ReportingTime as attribute for a Employee element.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;FONT color=#111111&gt;&lt;/FONT&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;FONT color=#111111&gt;That message is because I am casting a value like '1975-03-14+05:30' in Datetime in Sql Server and sql server donot store timezone information in the field itself.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;FONT color=#111111&gt;&lt;/FONT&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;FONT color=#111111&gt;I have only option to use string datatype in schema &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;FONT color=#111111&gt;&lt;/FONT&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;FONT color=#111111&gt;Is there any other method ....&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&lt;/SPAN&gt; &lt;/P&gt;</description><pubDate>Wed, 01 Aug 2007 11:45:00 GMT</pubDate><dc:creator>dinesh sodani</dc:creator></item><item><title>XML Workshop VII - Validating values with SCHEMA</title><link>http://www.sqlservercentral.com/Forums/Topic382155-356-1.aspx</link><description>Comments posted here are about the content posted at &lt;A HREF="http://www.sqlservercentral.com/columnists/jSebastian/3120.asp"&gt;http://www.sqlservercentral.com/columnists/jSebastian/3120.asp&lt;/A&gt;</description><pubDate>Mon, 16 Jul 2007 17:33:00 GMT</pubDate><dc:creator>jacob sebastian</dc:creator></item></channel></rss>