Wednesday, March 21, 2012

Referencing xs:schema within a SCHEMA COLLECTION

Hi all,
I have an XML schema that has an element declaration that references a W3C
XML Schema type:
<xs:import namespace="http://www.w3.org/2001/XMLSchema"/>
. . .
<xs:element ref="xs:schema"/>
When I try and import this schema into a SQL SCHEMA COLLECTION, I get an
error:
Msg 2308, Level 16, State 1, Line 1
Reference to an undefined name 'schema' within namespace
'http://www.w3.org/2001/XMLSchema'
The problem is obviously that the schema processor does not have a copy of
the W3C XML Schema, uh, schema handy. I tried getting a copy of the XML
Schema reference from the W3C and cleaning up the documentation nodes
(riddled with single quotes). The schema processor then gave me an "invalid
target namespace specified error.
Any ideas for having a node that contains a schema? How would the schema
for WSDL be accepted? Thanks,
- ErikHi Eric,
You don't need to import the schema for schemas (apparently it even causes
problems) because its built-in to SQL Server 2005. Just refer to it in your
schema. Like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ...more >
...
<xs:element name="yourtype" type="xs:string" />
</xs:schema>
Deriving types would work the same way.
Weird error message, I'll admit.
Hope this helps,
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
"Erik J." <ErikJ@.discussions.microsoft.com> wrote in message
news:E4DBFFC7-28FF-4C89-BD0A-F31502BA3E36@.microsoft.com...
> Hi all,
> I have an XML schema that has an element declaration that references a W3C
> XML Schema type:
> <xs:import namespace="http://www.w3.org/2001/XMLSchema"/>
> . . .
> <xs:element ref="xs:schema"/>
> When I try and import this schema into a SQL SCHEMA COLLECTION, I get an
> error:
> Msg 2308, Level 16, State 1, Line 1
> Reference to an undefined name 'schema' within namespace
> 'http://www.w3.org/2001/XMLSchema'
> The problem is obviously that the schema processor does not have a copy of
> the W3C XML Schema, uh, schema handy. I tried getting a copy of the XML
> Schema reference from the W3C and cleaning up the documentation nodes
> (riddled with single quotes). The schema processor then gave me an
> "invalid
> target namespace specified error.
> Any ideas for having a node that contains a schema? How would the schema
> for WSDL be accepted? Thanks,
> - Erik
>|||Thanks Bob.
If I declare the schema type as xs:string, I'll have to escape XML markup in
the embedded schema node. The work-around I picked instead was to declare a
n
xs:any rather than an xs:element. I can tell the schema process to skip
processing on the embedded node that way.
But I really wanted to have SQL Server validate my documents fully,
including the embedded schemas. I'll think about that over the wend and
let everyone know what I come up with.
Cheers,
Erik Johnson
http://appside.blogspot.com
"Bob Beauchemin" wrote:

> Hi Eric,
> You don't need to import the schema for schemas (apparently it even causes
> problems) because its built-in to SQL Server 2005. Just refer to it in you
r
> schema. Like this:
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ...more >
> ...
> <xs:element name="yourtype" type="xs:string" />
> </xs:schema>
> Deriving types would work the same way.
> Weird error message, I'll admit.
> Hope this helps,
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
>
> "Erik J." <ErikJ@.discussions.microsoft.com> wrote in message
> news:E4DBFFC7-28FF-4C89-BD0A-F31502BA3E36@.microsoft.com...
>
>|||Hi Erik, could you please send me email to describe what you would like to
do? We then can take a look at why it is not working.
Note that the Schema for the W3C Schema is not a valid schema in its own.
Best regards
Michael
"Erik J." <ErikJ@.discussions.microsoft.com> wrote in message
news:228DE552-E347-4906-A1E0-F321E00FF3BC@.microsoft.com...
> Thanks Bob.
> If I declare the schema type as xs:string, I'll have to escape XML markup
> in
> the embedded schema node. The work-around I picked instead was to declare
> an
> xs:any rather than an xs:element. I can tell the schema process to skip
> processing on the embedded node that way.
> But I really wanted to have SQL Server validate my documents fully,
> including the embedded schemas. I'll think about that over the wend
> and
> let everyone know what I come up with.
> Cheers,
> Erik Johnson
> http://appside.blogspot.com
> "Bob Beauchemin" wrote:
>|||Hi Michael,
Thanks for looking into this. We are creating some schemas for XML
documents that contain XML schemas. Here is a simple example:
CREATE XML SCHEMA COLLECTION TestSchemas AS
'<xs:schema id="Noun"
targetNamespace="http://tempuri.org/Noun.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/Noun.xsd"
xmlns:mstns="http://tempuri.org/Noun.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.w3.org/2001/XMLSchema" />
<xs:element name="Noun">
<xs:complexType>
<xs:sequence>
<xs:element ref="xs:schema" />
</xs:sequence>
<xs:attribute name="uri" use="required">
<xs:simpleType>
<xs:restriction base="xs:anyURI"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>'
I get this message:
Msg 2308, Level 16, State 1, Line 1
Reference to an undefined name 'schema' within namespace
'http://www.w3.org/2001/XMLSchema'
And you are right. The sample XSD on the W3C website is not usable,
although I tried to shoehorn it! Thanks again,
- Erik
"Michael Rys [MSFT]" wrote:

> Hi Erik, could you please send me email to describe what you would like to
> do? We then can take a look at why it is not working.
> Note that the Schema for the W3C Schema is not a valid schema in its own.
> Best regards
> Michael
> "Erik J." <ErikJ@.discussions.microsoft.com> wrote in message
> news:228DE552-E347-4906-A1E0-F321E00FF3BC@.microsoft.com...
>
>|||I see. Even if you remove the import, this fails. Also means that I can't
catalog the schemas in the WSDL file put out by SQL Server 2005 XML Web
Services feature. For example,
http://schemas.microsoft.com/sqlserver/2004/SOAP/types. Even if I change the
target namespace. Hmmm...
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
"Erik J." <ErikJ@.discussions.microsoft.com> wrote in message
news:EDC61844-1E9B-4B71-8B15-4686FAAB8A5F@.microsoft.com...
> Hi Michael,
> Thanks for looking into this. We are creating some schemas for XML
> documents that contain XML schemas. Here is a simple example:
> CREATE XML SCHEMA COLLECTION TestSchemas AS
> '<xs:schema id="Noun"
> targetNamespace="http://tempuri.org/Noun.xsd"
> elementFormDefault="qualified"
> xmlns="http://tempuri.org/Noun.xsd"
> xmlns:mstns="http://tempuri.org/Noun.xsd"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <xs:import namespace="http://www.w3.org/2001/XMLSchema" />
> <xs:element name="Noun">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="xs:schema" />
> </xs:sequence>
> <xs:attribute name="uri" use="required">
> <xs:simpleType>
> <xs:restriction base="xs:anyURI"/>
> </xs:simpleType>
> </xs:attribute>
> </xs:complexType>
> </xs:element>
> </xs:schema>'
> I get this message:
> Msg 2308, Level 16, State 1, Line 1
> Reference to an undefined name 'schema' within namespace
> 'http://www.w3.org/2001/XMLSchema'
> And you are right. The sample XSD on the W3C website is not usable,
> although I tried to shoehorn it! Thanks again,
> - Erik
>
> "Michael Rys [MSFT]" wrote:
>

No comments:

Post a Comment