Could you write a XSD file for the requirements? thanks!
1. The Folder elements and the Bookmarks element can occur with free order
2. The Folder elements can occur 0 or unbounded times
3. The Bookmark elements can occur 0 or unbounded times
I have made the following code Part A-1 and Part A-2, they work well, the only problem is that the Folder elements must be at front of the Bookmark elements.
So I have to write the code Part B-1 and Part B-2, but I get the following error:
.Net SqlClient Data Provider: Msg 6965, Level 16, State 1, Line 3
XML Validation: Invalid content. Expected element(s):http://www.hellocw.com/onlinebookmark:Folder where element 'http://www.hellocw.com/onlinebookmark:Bookmark' was specified. Location: /*:Folder[1]/*:Folder[1]/*:Bookmark[1]
//--------Part A-1----------
CREATE XML SCHEMA COLLECTION [dbo].[bookmarkxsd]
AS N'
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.hellocw.com/onlinebookmark"
targetNamespace="http://www.hellocw.com/onlinebookmark"
elementFormDefault="qualified">
<xsd:element name="Folder" type="folderType"/>
<xsd:complexType name="bookmarkType">
<xsd:attribute name="BId" type="xsd:string" />
<xsd:attribute name="Title" type="xsd:string" />
<xsd:attribute name="Url" type="xsd:string" />
<xsd:attribute name="Description" type="xsd:string" />
<xsd:attribute name="InputDate" type="xsd:string" />
<xsd:attribute name="IsPrivate" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="folderType">
<xsd:sequence>
<xsd:element name="Folder" type="folderType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="Bookmark" type="bookmarkType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="Name" type="xsd:string" />
<xsd:attribute name="Id" type="xsd:string" />
</xsd:complexType>
</xsd:schema>
'
GO
//--------Part A-1----------
//--------Part A-2----------
Delete from cw_bookmark where UserId='61809B69-4AD5-40E4-B456-D957C78DD99E'
go
INSERT INTO cw_Bookmark (UserID,Bookmark) VALUES ('61809B69-4AD5-40E4-B456-D957C78DD99E',
'
<Folder xmlns="http://www.hellocw.com/onlinebookmark" Name="Root" Id="a6dce8fe-749c-4e38-ab2f-3d03d9711b3d">
<Folder Name="Card" Id="b8dcf8fe-749c-4e38-ab2f-6d03d9711b8j">
<Folder Name="Type" Id="hkdcf8fe-749c-4e38-ab2f-6d03d9711bfg">
</Folder>
<Bookmark BId="ghdce3ak-456c-4e38-ab2f-5h02d9711b67"
Title="Welcome to ePassporte"
Url="https://www.epassporte.com/"
Description="This is a big site"
InputDate="2004-08-12"
IsPrivate="false">
</Bookmark>
<Bookmark BId="fkdfh3a8-456c-6y38-jk2f-5h0gh9711b45"
Title="Keystone DreamCard"
Url="https://www.mydreamcardonline.com"
Description="Please note"
InputDate="2004-09-25"
IsPrivate="false">
</Bookmark>
</Folder>
<Folder Name="CD" Id="f5dcf8fe-749c-4e38-ab2f-6d03d9711bdf">
</Folder>
<Bookmark BId="f8dce8hj-846c-4e38-ab2f-6d03d9711b80"
Title="CodeGuru Forums - ASP.NET"
Url="http://www.codeguru.com/"
Description="This is a good site"
InputDate="2005-10-29"
IsPrivate="false">
</Bookmark>
<Bookmark BId="fgdce3ak-846c-4e38-ab2f-8i03d9711b23"
Title="We ll e-mail your press release"
Url="http://www.dpdirectory.com/"
Description="This is a new site"
InputDate="2004-11-23"
IsPrivate="true">
</Bookmark>
</Folder>
')
//--------Part A-2----------
//--------Part B-1----------
CREATE XML SCHEMA COLLECTION [dbo].[bookmarkxsd]
AS N'
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.hellocw.com/onlinebookmark"
targetNamespace="http://www.hellocw.com/onlinebookmark"
elementFormDefault="qualified">
<xsd:element name="Folder" type="folderType"/>
<xsd:complexType name="bookmarkType">
<xsd:attribute name="BId" type="xsd:string" />
<xsd:attribute name="Title" type="xsd:string" />
<xsd:attribute name="Url" type="xsd:string" />
<xsd:attribute name="Description" type="xsd:string" />
<xsd:attribute name="InputDate" type="xsd:string" />
<xsd:attribute name="IsPrivate" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="folderType">
<xsd:choice>
<xsd:element name="Folder" type="folderType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="Bookmark" type="bookmarkType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:choice>
<xsd:attribute name="Name" type="xsd:string" />
<xsd:attribute name="Id" type="xsd:string" />
</xsd:complexType>
</xsd:schema>
'
GO
//--------Part B-1----------
//--------Part B-2----------
Delete from cw_bookmark where UserId='61809B69-4AD5-40E4-B456-D957C78DD99E'
go
INSERT INTO cw_Bookmark (UserID,Bookmark) VALUES ('61809B69-4AD5-40E4-B456-D957C78DD99E',
'
<Folder xmlns="http://www.hellocw.com/onlinebookmark" Name="Root" Id="a6dce8fe-749c-4e38-ab2f-3d03d9711b3d">
<Folder Name="Card" Id="b8dcf8fe-749c-4e38-ab2f-6d03d9711b8j">
<Folder Name="Type" Id="hkdcf8fe-749c-4e38-ab2f-6d03d9711bfg">
</Folder>
<Bookmark BId="ghdce3ak-456c-4e38-ab2f-5h02d9711b67"
Title="Welcome to ePassporte"
Url="https://www.epassporte.com/"
Description="This is a big site"
InputDate="2004-08-12"
IsPrivate="false">
</Bookmark>
<Bookmark BId="fkdfh3a8-456c-6y38-jk2f-5h0gh9711b45"
Title="Keystone DreamCard"
Url="https://www.mydreamcardonline.com"
Description="Please note"
InputDate="2004-09-25"
IsPrivate="false">
</Bookmark>
</Folder>
<Folder Name="CD" Id="f5dcf8fe-749c-4e38-ab2f-6d03d9711bdf">
</Folder>
<Bookmark BId="f8dce8hj-846c-4e38-ab2f-6d03d9711b80"
Title="CodeGuru Forums - ASP.NET"
Url="http://www.codeguru.com/"
Description="This is a good site"
InputDate="2005-10-29"
IsPrivate="false">
</Bookmark>
<Bookmark BId="fgdce3ak-846c-4e38-ab2f-8i03d9711b23"
Title="We ll e-mail your press release"
Url="http://www.dpdirectory.com/"
Description="This is a new site"
InputDate="2004-11-23"
IsPrivate="true">
</Bookmark>
</Folder>
')
//--------Part B-2----------

