Reputation: 669
I have an XSD file that I use to validate some XML data, and on my own PC this works perfectly. However when on a computer without a network, it fails with this error
Server was unable to process request. ---> Type 'http://schemas.microsoft.com/sqlserver/2004/sqltypes:nvarchar' is not declared, or is not a simple type.
Yet this works perfectly elsewhere.
The start of my XSD file is as follows
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:schema="DataLoad" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
After some research, I've tried changed the schemaLocation
attribute to
schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes ./bin/sqlTypes.xsd"
Apparently, that should load from ./bin/sqlTypes.xsd
then (I saved a local copy of the MS one to ./bin/sqlTypes.xsd
But now, I get this error...
Server was unable to process request. ---> Cannot load the schema from the location 'http://schemas.microsoft.com/sqlserver/2004/sqltypes ./bin/sqltypes.xsd' - The root element of a W3C XML Schema should be and its namespace should be 'http://www.w3.org/2001/XMLSchema'..
I'm new to XML Schemas and still trying to get my head around this.
Upvotes: 4
Views: 12833
Reputation: 12187
OK, it looks like schemaLocation
has a different syntax in that context (crazy, right?). Normally, it takes "$namespace $address" (i.e. two arguments, separated by a space - actually, a list of such pairs), as you say.
But in an <import>
element, there is a special attribute for namespace (called namespace
), and the schemaLocation
now contains the address only. Does that make any sense? No. Here's what I think it means for your example:
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes"
schemaLocation="./bin/sqlTypes.xsd" />
Here's the spec defining <import>
, and the schemaLocation
is clearly just an uri:
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#composition-schemaImport
For comparison, here is the definition of <xsi:schemaLocation>
(note the "xsi" - it's in a different namespace, so they can have different definitions, it's just that it's unnecessarily confusing to use the same name):
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#xsi.schemaLocation
The xml schema "primer" also distinguishes between these uses: http://www.w3.org/TR/xmlschema-0/#schemaLocation
Upvotes: 2
Reputation: 6003
The Schema location attribute contains pairs of values "namespace" followed by "schema location".
On your local machine your application seems able to magically resolve the schema from just namespace "http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" and load the schema (or it does no validation). I would need to know how its loading the XML files to determine how this namespace to schema location mapping is performed.
Note although the namespace "http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" looks like a url it is just a token, and does not directly tell the parser where the schema is.
Adding the "./bin/sqlTypes.xsd" tells the parser it can load the file from a relative path from the XML file being loaded. For this to work the XSD file (and all its imports/includes) need to be at this location, I'm guessing there not?
Upvotes: 0