Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when generating a class from xsd schema file

Tags:

c#

xsd

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

like image 410
Amokrane Chentir Avatar asked Jun 16 '10 15:06

Amokrane Chentir


1 Answers

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.

like image 196
marc_s Avatar answered Oct 06 '22 23:10

marc_s