首页 > 解决方案 > 类型属性的 XSD 问题:类型属性不能与 simpleType 或 complexType 一起出现

问题描述

我已经在 stackoverflow 上寻找了答案,但不幸的是,所有的分析器都不适合我:

我有以下xml:

<STGDocument version="3" workitem-id="0" index="1">
       <ID type="String">ab78e02c-a472-45b9-99d0-57c19034a51b</ID>
....

以及从网页生成的 XSD:

<xs:element name="STGDocument">
<xs:complexType>
  <xs:sequence>
    <xs:element name="ID" type="xs:string">
      <xs:complexType>
        <xs:attribute name="type" type="xs:string"></xs:attribute>
      </xs:complexType>
    </xs:element>
.......

不知何故,<xs:element name "Id" ....>标签抛出错误“类型属性不能与 simpleType 或 complexType 一起出现”

我怎样才能解决这个问题?

如前所述,我在 SOF 上尝试了所有解决方案,但没有一个对我有用......

纳克斯

标签: xmltypesxsd

解决方案


元素的类型要么使用type属性(如type="xs:string")声明,要么使用嵌套xs:simpleTypexs:complexType元素声明。你不能两者兼得,这就是它抱怨的原因。

您的 ID 元素的实际类型是“具有简单内容的复杂类型”,应按以下示例声明:XSD : How to use both value and attribute


推荐阅读