Cookies on

This web site uses some strictly nesessary cookies to make this web site work.

We would also like to set additional cookies to understand how you use, remember your settings and improve our services.

Using import or include with xsd.exe

I have recently been playing around with XML schemas and creating class models from them using xsd.exe (see MSDN).

I ran into a stumbling block, however, when I tried to use it to generate classes from a schema that used the <xsd:import> statement to import another schema. Although it is not very obvious from the documentation, it does support this, however it does not support the schemaLocation hint.

In order to use schemas that import or include other schemas you need to specify both the base schema and the imported schema on the command line.

For example if you have the following two schemas:


<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace=""

    <xs:import namespace="" schemaLocation="XMLSchema2.xsd" />

   <xs:element name="example">
                <xs:element name="test" type="examp2:myType" />


<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace=""
    <xs:complexType name="myType">
            <xs:element name="test" type="xs:string" />

You would need to use the following command line:

xsd.exe schema1.xsd schema2.xsd /c


Re: Using import or include with xsd.exe

Useful tip about adding name of included schema in xsd.exe command line. However, this only seems to be necessary with &lt;xs:import&gt;. When using &lt;xs:include&gt; it takes account of the schemaLocation.

Comment from Tim at Thursday, 30 March 2006 09:33AM (GMT+00)

Sorry, this post is no longer accepting comments.