Scott Hanselman

XSD.exe is kicking my butt, man...redux

April 25, 2003 Comment on this post [5] Posted in Web Services | XML | Tools
Sponsored By

Decomposing XSD and WSDL into abstract definitions of types and messages is a good thing, but it appears that Microsoft’s tools don’t adequately support embracing this approach? Or, I'm completely sans clue.  For example, XSD.exe doesn’t seem to be able to cope with xs:import elements when generating wrapper classes.  WSDL.exe has the same problem. 

Anyone have any thoughts on this?  I'd like NOT to wait until Whidbey to be able to describe my messages and contracts and generate a schtickel of code.  Updated with Note: Rant retracted...for now! See below ;)

Here’s a very trivial example straight from Dare's great MSDN Article.


<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs= 
      <xs:complexType name="rootType" >  
                  <xs:element name="child1" type="xs:string" maxOccurs="2" />
                  <xs:element name="child2" type="xs:string"/>

The Outer xsd:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="
<xs:import namespace="" schemaLocation="file:///c:/import.xsd"/>
 <xs:element name="root" type="imp:rootType" />

This schema appears to be valid – in fact, the .NET framework agrees.  But when you try and run the outer schema through xsd.exe, you get the following error:

C:\>xsd /c root.xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Schema validation warning: Type '' is not declared
. An error occurred at file:///C:/root.xsd, (10, 3).

Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.

Error: Error generating classes for schema 'root'.
  - The datatype '' is missing.

Update: Tomas was kind enough to point out not only that I had originally posted the same schema TWICE, doh!  But also, more importantly, that XSD.EXE doesn't resolve schemaLocation on imports or includes, presuambly because the W3C Schema spec describes the schemaLocation attribute as a hint, not a true location.

I'm back in business as I ran XSD.EXE again with all necessary files specified on the commandline, in order to give XSD.EXE a choice of namespaces - as opposed to hoping it would somehow glean my intent!

I'm too used to using XMLSpy, XSLT and other tools for generating CS code.  Good stuff, thanks Tomas!  Not only was I without a clue, I was also sin una pistasans indice - Ich war ohne einen Anhaltspunkt.  That'll teach me not to post a rant in haste! 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
April 26, 2003 4:46
Scott: Is it me, or did you post twice the same XSD snippet?

April 26, 2003 11:51
I posted once, then corrected an error in categories and posted again...

April 26, 2003 11:57
You know, it's 1am, but the more I look at this the more I realize that Tomas is probably right and I'm even wondering why I even thought it could work the way I was doing it. Of course! How could it infer where the schema was unless I tell it...we shall see when I wake up. Gracias Tomas.
April 26, 2003 12:05
Wow, I AM falling apart...I posted the same schema twice...fixing that, then checking my temperature! :)
May 22, 2004 0:41

I am struggling with a similiar issue. You said that you have to explicitely tell XSD.exe the schema location. Can you please give an example of the command line syntax> Also, will fully qualified path in xs:import resolve this issue?


Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.