Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD SCHEMA creation and use in T-SQL

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
US
I've tried everything I can to create an XML SCHEMA in SQL Server 2008.

Maybe someone can help. Here's the XML that I need a schema for:

<NODE><GUID>e4933d5d-7452-4fad-b557-125d700da000</GUID></NODE>

Here is my original XSD SCHEMA that successfully 'compiled' into a XML SCHEMA:

CREATE XML SCHEMA COLLECTION [dbo].[GUIDSchema]
AS
N'<xsd:schema xmlns:xsd=" <xsd:element name="NODE">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="GUID" type="xsd:anyType" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>'
GO

Here is the function that makes use of the schema:
ALTER FUNCTION [dbo].[fnGUID_from_XML] ( @inputXML XML )
RETURNS uniqueidentifier
AS
BEGIN
DECLARE @ValidateXML as XML(GUIDSchema)
SET @ValidateXML = @inputXML

DECLARE @GUID as uniqueidentifier
DECLARE @PL_FILE TABLE (TempGUID uniqueidentifier )

INSERT INTO @PL_FILE (TempGUID)
SELECT ParamValues.Items.value('GUID[1]','uniqueidentifier')
FROM @ValidateXML.nodes('/NODE') as ParamValues(Items)

select @GUID = TempGUID from @PL_FILE
RETURN @GUID
END

However, when I try to compile the above function, I get this error:
Msg 9314, Level 16, State 1, Procedure fnGUID_from_XML, Line 18
XQuery [value()]: Cannot implicitly atomize or apply 'fn:data()' to complex content elements, found type 'xs:anyType' within inferred type 'element(GUID,xs:anyType) ?'.


I have tried removing the various <xsd...> tags from the schema, but can never compile the schema again. The only code that creates a successful schema compilation is what I've provided here.

Thanks in advance,

Jerry Scannell
 
Nastia,

1. I'm not doing this on the internet. It's within SQL Server.

2. I'm not creating any files anywhere. I'm not sure how you thought that.

Thanks,

Jerry Scannell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top