Local circuit

I have an XSD file that I use to validate some XML data, and it works fine on my own PC. However, when on a computer without a network it does not work with this error

The server was unable to process the request. ---> The type ' http://schemas.microsoft.com/sqlserver/2004/sqltypes:nvarchar ' is not declared or is not a simple type.

But it works great elsewhere.

The beginning 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 tried changing the schemaLocation attribute to

 schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes ./bin/sqlTypes.xsd" 

Apparently this should load from ./bin/sqlTypes.xsd then (I saved a local copy of MS one to ./bin/sqlTypes.xsd

But now I get this error ...

The server was unable to process the request. ---> Unable to load the schema from the location http://schemas.microsoft.com/sqlserver/2004/sqltypes ./bin/sqltypes.xsd '- the root XML element of W3C The schema must be and its namespace must be http: //www.w3.org/2001/XMLSchema '..

I am new to XML Schemas and still trying to think it over.

+4
source share
2 answers

OK, it looks like schemaLocation has a different syntax in this context (crazy, right?). Typically, it takes a "$ namespace $ address" (that is, two arguments separated by a space - in fact, a list of such pairs), as you say.

But the <import> element has a special attribute for the namespace (called namespace ), and schemaLocation now only contains the address. Does this make sense? Not. Here I think this means for your example:

 <xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="./bin/sqlTypes.xsd" /> 

Here's the specification defining <import> , and schemaLocation is clearly just a uri: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#composition-schemaImport

For comparison, here is the definition of <xsi:schemaLocation> (pay attention to "xsi" - it is in a different namespace, so they can have different definitions, it's just that it’s just unnecessarily confusing the same name): http: //www.w3 .org / TR / 2004 / REC-xmlschema-1-20041028 / structures.html # xsi.schemaLocation

The primer xml scheme also distinguishes between these uses: http://www.w3.org/TR/xmlschema-0/#schemaLocation

+1
source

The schema location attribute contains pairs of "namespace" values ​​followed by "schema location".

On your local machine, your application seems to be able to magically resolve the schema only from the namespace "http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" and load the schema (or it does not check). I need to know how its loading XML files to determine how this namespace is used to map the location of the schema.

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 circuit is located.

Adding "./bin/sqlTypes.xsd" tells the parser that it can load the file from the relative path from the loaded XML file. To do this, you need to work with the XSD file (and all its imports / included), I assume not?

0
source

Source: https://habr.com/ru/post/1399156/


All Articles