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
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