|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, June 04, 2012 6:07 AM
Points: 2,
Visits: 38
|
|
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. x.item.value('Employee\@ReportingTime[1]', 'Datetime') AS ReportingTime Let say ReportingTime as attribute for a Employee element. 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. I have only option to use string datatype in schema Is there any other method ....
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
dinesh, 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. 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. DECLARE @emp AS XMLSET @emp = ' <Employee EmployeeNumber="1001" Language="EN" > <FullName>Jacob</FullName> <Salary>10000</Salary> <Age>30</Age> <Married>1</Married> <BirthDate>1975-03-14T12:00:00+05:30</BirthDate> <ReportingTime /> </Employee> ' SELECT x.e.value('@EmployeeNumber[1]','varchar(20)') as EmpNumber, x.e.value('FullName[1]','varchar(40)') as FullName, x.e.value('xs:dateTime(BirthDate[1])', 'datetime') as BirthDate FROM @emp.nodes('Employee') x(e)
.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 12:04 PM
Points: 612,
Visits: 209
|
|
Hello Jacob, 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? Thank you once again for your articles.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 12:29 AM
Points: 173,
Visits: 317
|
|
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
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
Hi Herit, There is an article in this series which explains the enumeration in detail. I am not sure what is the scheduled date. But I guess it will be out in a week. thanks Jacob
.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, April 16, 2013 7:20 AM
Points: 11,
Visits: 90
|
|
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
DECLARE @emp AS XML(EmployeeSchema) SET @emp = '' 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
DECLARE @emp AS XML(EmployeeSchema) SET @emp = 'put a valid xml comment here' 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.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
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:
DECLARE @x XML(DOCUMENT EmployeeSchema)
.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, April 16, 2013 7:20 AM
Points: 11,
Visits: 90
|
|
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.
Msg 102, Level 15, State 1, Line 32 Incorrect syntax near 'year'.
xsd collection attached
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Saturday, May 11, 2013 8:17 AM
Points: 460,
Visits: 2,521
|
|
The regular expression language is documented here: http://www.w3.org/TR/xmlschema-2/#regexs The 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/
.
|
|
|
|