简体   繁体   English

从xsd模式文件生成类时出错

[英]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: 我正在尝试从xsd架构生成一个类,但我收到以下错误消息:

Warning: cannot generate classes because no top-level elements with complex type were found. 警告:无法生成类,因为找不到具有复杂类型的顶级元素。

My xsd file looks like that: 我的xsd文件看起来像这样:

<?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). 注意我已经定义了一个复杂类型的顶级元素(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. 然后一切都应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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