xsd.exe and the xs:import element
Jan. 7th, 2010 10:12 amI have spent a largely unprofitable hour trying to work out why xsd.exe couldn't parse a specific .xsd file I was presenting it with.
If, for example, the parent .xsd has a namespace reference of
...xmlns:sf="http://slowfox.dreamwidth.org/"...
followed by animport element
<xs:import namespace="http://slowfox.dreamwidth.org/" schemaLocation="SlowFox.xsd"/>
then when running the xsd tool from the Visual Studio command prompt, you get the following error message:
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
The answer, which I learnt courtesy of Scott Hanselman's blog is to provide all the dependent files on the command line, in addition to the parent .xsd.
So you'd run
xsd.exe /c MainSchemaDefinition.xsd SlowFox.xsd
which produces the desired result (C# classes generated automagically from the .xsd).
The issue, apparently, is that the xsd tool can't handle the xs:import element (despite the fact that you've given it an exact file name to match against the specified namespace), but if you provide all the consituent files as part of the command's argument, xsd.exe knows where to try and look for the various dependencies it stumbles across.
If, for example, the parent .xsd has a namespace reference of
...xmlns:sf="http://slowfox.dreamwidth.org/"...
followed by an
<xs:import namespace="http://slowfox.dreamwidth.org/" schemaLocation="SlowFox.xsd"/>
then when running the xsd tool from the Visual Studio command prompt, you get the following error message:
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
The answer, which I learnt courtesy of Scott Hanselman's blog is to provide all the dependent files on the command line, in addition to the parent .xsd.
So you'd run
xsd.exe /c MainSchemaDefinition.xsd SlowFox.xsd
which produces the desired result (C# classes generated automagically from the .xsd).
The issue, apparently, is that the xsd tool can't handle the xs:import element (despite the fact that you've given it an exact file name to match against the specified namespace), but if you provide all the consituent files as part of the command's argument, xsd.exe knows where to try and look for the various dependencies it stumbles across.