无法在本地引用sqltypes架构xsd

时间:2016-05-05 21:00:15

标签: xml tsql xsd

我正在使用我从T-sql生成的xml文件来模拟一些数据访问,如:

SELECT * FROM dbo.my_table FOR XML AUTO, XMLSCHEMA 

这会生成一个工作文件,因为schemaLocation处的xsd是在线托管的:

  <xsd:schema targetNamespace="mydata" xmlns:schema="mydata" 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" />
    <xsd:element name="dbo.my_table">
      <xsd:complexType>
        <xsd:attribute name="Id" type="sqltypes:int" use="required" />
        <xsd:attribute name="Foo" type="sqltypes:int" use="required" />
        ...etc, etc.

我的测试运行时无法依赖互联网连接,因此我想将其存储在本地。所以我下载了xsd并将它放在与我的数据的xml相同的文件夹中并引用它:

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

无法解析schemaLocation属性

当然,我已尝试过各种方法来引用此方法,但有效方法除外。

正确的语法是什么?

1 个答案:

答案 0 :(得分:1)

在某些环境中,当前目录的定义会变得模糊。

尝试使用绝对路径:

schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes 
                file:///c:/path/to/sqltypes.xsd"

如果这不起作用,请按照此Stack Overflow问题的答案中的说明,通过浏览器检查您的路径规范:How to reference a local XML Schema file correctly?

相关问题