tags:

views:

99

answers:

1

Hi,

I'm trying to generate a class from an xsd schema but I obtain the following error message:

Warning: cannot generate classes because no top-level elements with complex type were found.

My xsd file looks like that:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="MonitoringConfiguration"
    targetNamespace="urn:MonitoringConfiguration-1.0"
    elementFormDefault="qualified"
    xmlns="urn:MonitoringConfiguration-1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

  <xs:complexType name="MonitoringConfiguration">
    <xs:sequence>
      <xs:element name="Machine" type="Machine" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Machine">
    <xs:sequence>
      <xs:element name="Component" type="Component" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Component">
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="Type" type="xs:string" use="optional"/>
  </xs:complexType>
</xs:schema>

I'm generating the class with the following command line:

xsd MonitoringConfiguration.xsd /languages:CS /Classes

Note I have already defined a top level element with complex type (MonitoringConfiguration).

What's wrong?

Thanks

+2  A: 

You have defined a top-level complex type - but no top-level element.

You need to add:

<xs:element name="MonitoringConfigurationElement" 
            type="MonitoringConfiguration" />

and then everything should be just fine.

marc_s
Indeed, it works!
Amokrane