从 xsd 模式文件生成类时出错 [英] Error when generating a class from xsd schema file

查看:23
本文介绍了从 xsd 模式文件生成类时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 xsd 架构生成一个类,但收到以下错误消息:

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

警告:无法生成类,因为找不到具有复杂类型的顶级元素.

我的 xsd 文件如下所示:

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

注意我已经定义了一个复杂类型的顶级元素(MonitoringConfiguration).

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

怎么了?

谢谢

推荐答案

您已经定义了顶级复杂类型 - 但没有顶级 元素.

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

您需要添加:

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

然后一切都会好起来的.

and then everything should be just fine.

这篇关于从 xsd 模式文件生成类时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆