Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CREATE XML SCHEMA COLLECTION - Expected XML schema document Error

329 views
Skip to first unread message

NMahmoud

unread,
Jan 27, 2010, 7:31:27 PM1/27/10
to
hi,

in SQL Server 2008,

I am trying to create a XML SCHEMA COLLECTION for the following xml, but I
am getting the error

Msg 2378, Level 16, State 1, Line 23
Expected XML schema document

any idea how can I do that!

thank you
Nabila


declare
@xmlStr xml

set @xmlStr = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="http://tempuri.org/">
<Username>string</Username>
<Password>string</Password>
<Domain>string</Domain>
</AuthenticationHeader>
<RequestInfoParameters xmlns="http://tempuri.org/">
<ContentLanguage>int</ContentLanguage>
</RequestInfoParameters>
</soap:Header>
<soap:Body>
<DeleteUserByID xmlns="http://tempuri.org/">
<UserId>long</UserId>
</DeleteUserByID>
</soap:Body>
</soap:Envelope>'

CREATE XML SCHEMA COLLECTION Ekt_UserCreate AS @xmlStr

Bob

unread,
Jan 28, 2010, 6:45:01 AM1/28/10
to
You need to pass it an XML Schema document, not just some XML, eg
example from BOL.

-- Create a sample database in which to load the XML schema collection.
CREATE DATABASE SampleDB
GO
USE SampleDB
GO
CREATE XML SCHEMA COLLECTION ManuInstructionsSchemaCollection AS
N'<?xml version="1.0" encoding="UTF-16"?>
<xsd:schema
targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"
xmlns
="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

<xsd:complexType name="StepType" mixed="true" >
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
<xsd:element name="tool" type="xsd:string" />
<xsd:element name="material" type="xsd:string" />
<xsd:element name="blueprint" type="xsd:string" />
<xsd:element name="specs" type="xsd:string" />
<xsd:element name="diag" type="xsd:string" />
</xsd:choice>
</xsd:complexType>

<xsd:element name="root">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="Location" minOccurs="1"
maxOccurs="unbounded">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="step" type="StepType"
minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="LocationID" type="xsd:integer"
use="required"/>
<xsd:attribute name="SetupHours" type="xsd:decimal"
use="optional"/>
<xsd:attribute name="MachineHours"
type="xsd:decimal" use="optional"/>
<xsd:attribute name="LaborHours" type="xsd:decimal"
use="optional"/>
<xsd:attribute name="LotSize" type="xsd:decimal"
use="optional"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>' ;
GO
-- Verify - list of collections in the database.
select *
from sys.xml_schema_collections
-- Verify - list of namespaces in the database.
select name
from sys.xml_schema_namespaces

-- Use it. Create a typed xml variable. Note collection name specified.
DECLARE @x xml (ManuInstructionsSchemaCollection)
GO
--Or create a typed xml column.
CREATE TABLE T (
i int primary key,
x xml (ManuInstructionsSchemaCollection))
GO
-- Clean up
DROP TABLE T
GO
DROP XML SCHEMA COLLECTION ManuInstructionsSchemaCollection
Go
USE Master
GO
DROP DATABASE SampleDB


Look at 'CREATE XML SCHEMA COLLECTION' in Books Online (BOL).

"NMahmoud" wrote:

> .
>

NMahmoud

unread,
Jan 28, 2010, 12:33:25 PM1/28/10
to

thanks Bob
your example worked perfectly fine,
but what I have is a soap message, and I am kind of new to xml, and not sure
if sql server would have a problem with that or not.
if I assign it to a xml variable, it will go through, so the server see it
as xml,
but can I create a schema collection for it or not, I am not sure.

thanks
Nabila

"Bob" <B...@discussions.microsoft.com> wrote in message
news:8F76C336-15C5-4154...@microsoft.com...

Bob

unread,
Jan 29, 2010, 5:16:01 AM1/29/10
to

Open the XML file in Visual Studio and use the 'Create Schema' option from
the XML menu. Alternately cut the XSD by hand.

This will form the basis of your XML SCHEMA COLLECTION.

Use Books Online for further info:

http://msdn.microsoft.com/en-us/library/ms187856(SQL.90).aspx

"NMahmoud" wrote:

> .
>

NMahmoud

unread,
Feb 4, 2010, 2:28:12 PM2/4/10
to
than you Bob,
it worked

Nabila

"Bob" <B...@discussions.microsoft.com> wrote in message

news:D86A86DA-4EB8-42AA...@microsoft.com...

jacobsebastian

unread,
Feb 19, 2010, 11:24:58 PM2/19/10
to
The XML you posted is not a valid XML Schema Document. I would suggest reading
this introductory article that explains how to create XML Schema Collections:
http://beyondrelational.com/xml/Typed-XML-and-SCHEMA-Collections.aspx
0 new messages