简体   繁体   中英

Error when generating a class from xsd schema file

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM