Home > Archive > MS SQL XML > January 2006 > xsd:date probems with xml schema collections









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author xsd:date probems with xml schema collections
Karl Prosser

2006-01-26, 8:23 pm

i have a project with a third party supplied schema (abotu 2000 lines of XSD
code), but am having problems (not when creating the XML schema collection)
when i am putting what should be valid xml into a xml variable of that type.
it is only erroring out where the type is xsd:date

the error is as follows

XML Validation: Invalid simple type value: '1967-08-13'. Location: .....

... i've made a simple example to dupicate the problem

here is the code to create the schema collection:
-------

create xml schema collection karltester as
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault
="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="adate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>'

----
that create the schema fine. However when i try to set what should be valid
xml i as beow
------
declare @mytest xml (karltester)
set @mytest =
'<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<adate>1/1/2005</adate>
</root>'

----
i get this error:
XML Validation: Invalid simple type value: '1967-08-13'. Location:
/*:root[1]/*:adate[1]

... all i can say is - HELP :) PLEASE HELP..


Brandon Berg [MSFT]

2006-01-27, 8:24 pm

"Karl Prosser" < KarlProsser@discussi
ons.microsoft.com> wrote in message
news:C3B90AB7-4447-4AC0-B72C- A74B3AE2ED41@microso
ft.com...
>
> However when i try to set what should be valid
> xml i as beow
> ------
> declare @mytest xml (karltester)
> set @mytest =
> '<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
> <adate>1/1/2005</adate>
> </root>'
>
> ----
> i get this error:
> XML Validation: Invalid simple type value: '1967-08-13'. Location:
> /*:root[1]/*:adate[1]


You're not really getting an error that says '1967-08-13' when you give it
'1/1/2005', are you?

Other than that, SQL Server 2005 requires that you specify a time zone for
any xs:date, xs:time, or xs:dateTime values. And, of course, 1/1/2005 is
invalid in any XSD implementation. Try 2005-01-01Z, instead. ('Z' indicates
UTC time zone.)

--
Brandon Berg
Software Design Engineer
Microsoft SQL Server


Karl Prosser

2006-01-27, 8:24 pm

oh yeah.. actually my date is 2005-01-01 sort of thing, i had just messed
with the example with different formats and posted the wrong example in the
post, sorry about that.
2005-01-01Z works.. but is this standard (for XML), as i am generating this
XML, comparing it against the schema the company provided and then submitting
it to that company. their system probably isn't sql server. I'm just not sure
it will accept 2005-01-01Z instead of 2005-01-01 (their supplied example is
just 2005-01-01')

Karl
Galex Yen [MSFT]

2006-01-27, 8:24 pm

The Z represents the timzeone +00:00. Timezones are part of the XSD standard.

Regards,
Galex Yen

"Karl Prosser" wrote:

> oh yeah.. actually my date is 2005-01-01 sort of thing, i had just messed
> with the example with different formats and posted the wrong example in the
> post, sorry about that.
> 2005-01-01Z works.. but is this standard (for XML), as i am generating this
> XML, comparing it against the schema the company provided and then submitting
> it to that company. their system probably isn't sql server. I'm just not sure
> it will accept 2005-01-01Z instead of 2005-01-01 (their supplied example is
> just 2005-01-01')
>
> Karl

Karl Prosser

2006-01-30, 3:23 am

is there something similar to this (which of course doesn't work) that would
produce a valid XML date with the Z

select cast (getdate() as XML)

as what i am currently using is rather odd looking (as well as the otehr
version i have seem that uses a different convert then just trims off the
time then adds the Z

replace(Convert(varc
har(20), P46_BirthDate,102),'
.','-')+'Z'

Karl


Galex Yen [MSFT]

2006-01-31, 8:25 pm

Karl,

There really isn't a better way at this time. Another alternative is to use
style 126 or 127 and substring the result to remove the time portion and then
add the desired timezone.

Regards,
Galex Yen

"Karl Prosser" wrote:

> is there something similar to this (which of course doesn't work) that would
> produce a valid XML date with the Z
>
> select cast (getdate() as XML)
>
> as what i am currently using is rather odd looking (as well as the otehr
> version i have seem that uses a different convert then just trims off the
> time then adds the Z
>
> replace(Convert(varc
har(20), P46_BirthDate,102),'
.','-')+'Z'
>
> Karl
>
>

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com