Error when generating a class from xsd schema file

旧巷老猫 提交于 2019-12-30 09:45:11

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3054687/error-when-generating-a-class-from-xsd-schema-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!