1

I am mocking some data access with xml files that I generate from T-sql like:

SELECT * FROM dbo.my_table FOR XML AUTO, XMLSCHEMA 

This generates a working file because the xsd at schemaLocation is hosted online:

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

I can't rely on an internet connection when my tests run so I want to store it locally. So I download the xsd and place it in the same folder as the xml with my data and reference it like:

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

Cannot resolve the schemaLocation attribute

Of course I have tried every combination of ways to reference this except the one that works.

What is the correct syntax?

Crowcoder
  • 11,250
  • 3
  • 36
  • 45

1 Answers1

1

The definition of the current directory can get fuzzy in some environments.

Try using an absolute path:

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

If that doesn't work, check your path specification via a browser as explained in the answer to this Stack Overflow question: How to reference a local XML Schema file correctly?

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I got it working, First with your advice of the file:/// protocol but I had to remove the namespace. Then I tried just `sqltypes.xsd` and it worked, but It was not working before. I am at a loss for why it suddenly started working when that was something I tried before, more than once. – Crowcoder May 05 '16 at 22:44
  • I'm glad you got it working. Keep in mind, though, that `noNamespaceSchemaLocation` is needed rather than `schemaLocation` if your XML is not in a namespace. Also, be sure to check that an intentionally introduced validation error is reported to you as expected and not just lost somewhere. – kjhughes May 05 '16 at 23:42