以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XQuery/XLink/XPointer/ 』  (http://bbs.xml.org.cn/list.asp?boardid=14)
----  在SQL 2005中,为什么当我插入时间元素时得到错误?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=14&rootid=&id=22694)


--  作者:mycwcgr
--  发布时间:10/1/2005 1:25:00 PM

--  在SQL 2005中,为什么当我插入时间元素时得到错误?
Why do I get error when I try to insert a XML docment with date element into SQL 2005 database?


When I the following XML with date element into database, I get the error information below, why?

.Net SqlClient Data Provider: Msg 6926, Level 16, State 1, Line 2
XML Validation: Invalid simple type value: '2005-12-23'. Location: /*:Folder[1]/*:Bookmark[1]/*:InputDate[1]


//---------------------------------XSD for Bookmark field------------------------------------------
CREATE XML SCHEMA COLLECTION [dbo].[mycollect]
AS N'

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="Folder" type="folderType"/>

  <xsd:complexType name="bookmarkType">
    <xsd:sequence>
      <xsd:element name="Title" type="xsd:string" />
      <xsd:element name="Url" type="xsd:string" />
      <xsd:element name="Description" type="xsd:string" />
      <xsd:element name="InputDate" type="xsd:date" />
      <xsd:element name="IsPrivate" type="xsd:boolean" />
    </xsd:sequence>

    <xsd:attribute name="BId" type="xsd:string" />

  </xsd:complexType>

  <xsd:complexType name="folderType">

    <xsd:all>
      <xsd:element name="Folder" type="folderType" minOccurs="0" />
      <xsd:element name="Bookmark" type="bookmarkType" minOccurs="0" />
    </xsd:all>

    <xsd:attribute name="Name" type="xsd:string" />
    <xsd:attribute name="Id" type="xsd:string" />

  </xsd:complexType>

</xsd:schema>

'
GO

//---------------------------------XSD for Bookmark field----------------------------------------------

//---------------------------------Insert XML with date element into database----------------------------

INSERT INTO cw_Bookmark (UserID,Bookmark) VALUES ('b50cf8fe-749c-4e38-ab2f-6d0ui9711brt',
'
<Folder Name="Root" Id="a6dce8fe-749c-4e38-ab2f-3d03d9711b3d">

  <Bookmark BId="f8dce8hj-846c-4e38-ab2f-6d03d9711b80">
    <Title>CodeGuru Forums - ASP.NET</Title>
    <Url>http://www.codeguru.com/</Url>
    <Description>This is a good site</Description>
    <InputDate>2005-12-23</InputDate>
    <IsPrivate>false</IsPrivate>
  </Bookmark>

  <Folder Name="Card1" Id="b8dcf8fe-749c-4e38-ab2f-6d03d9711b8j">

    <Bookmark BId="fkdfh3a8-456c-6y38-jk2f-5h0gh9711b45">
      <Title>Keystone DreamCard</Title>
      <Url>https://www.mydreamcardonline.com</Url>
      <Description>Please note</Description>
      <InputDate>2004-09-25</InputDate>
      <IsPrivate>true</IsPrivate>
    </Bookmark>

    <Folder Name="Card1in1" Id="l9dcf8fe-689c-0935-fghj-7u03d9711b5t">
       <Bookmark BId="ghdfh3a8-896c-6y40-jkfg-5h0gh9711b89">
         <Title>The News of CNN</Title>
         <Url>https://www.cnn.com</Url>
         <Description>Please note</Description>
         <InputDate>2004-09-23</InputDate>
         <IsPrivate>True</IsPrivate>
       </Bookmark>
    </Folder>

  </Folder>

</Folder>

')

//---------------------------------Insert XML with date element into database----------------------------


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms