首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套simpleType在complexType中

嵌套simpleType在complexType中
EN

Stack Overflow用户
提问于 2014-12-01 21:25:20
回答 1查看 1.6K关注 0票数 2

下面的代码在验证过程中给出了以下错误。这是否意味着我不能在simpleType元素中嵌套complexType元素?

Error - Line 18, 17: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 17; s4s-elt-must-match.1: The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*). A problem was found starting at: simpleType.

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.example.org/carType"
    elementFormDefault="qualified">

    <element name="carType">
        <complexType>
            <sequence>
                <simpleType name="colour">
                    <restriction base="string">
                        <enumeration value="blue" />
                        <enumeration value="yellow" />
                        <enumeration value="green" />
                        <enumeration value="black" />
                        <enumeration value="white" />
                    </restriction>
                </simpleType>
                <simpleType name="body">
                    <restriction base="string">
                        <enumeration value="sedan" />
                        <enumeration value="hatchback" />
                    </restriction>
                </simpleType>
            </sequence>
        </complexType>
    </element>
</schema>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-01 21:56:15

,你快到了。只需对XSD做两个小的调整:

  1. 在有<simpleType name="colour">的地方,应该声明一个colour元素:
  2. 类似地,在有<simpleType name="body">的地方,可以声明一个body元素:

那么,总共是

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://www.example.org/carType"
        elementFormDefault="qualified">
  <element name="carType">
    <complexType>
      <sequence>
        <element name="colour">
          <simpleType>
            <restriction base="string">
              <enumeration value="blue" />
              <enumeration value="yellow" />
              <enumeration value="green" />
              <enumeration value="black" />
              <enumeration value="white" />
            </restriction>
          </simpleType>
        </element>
        <element name="body">
          <simpleType>
            <restriction base="string">
              <enumeration value="sedan" />
              <enumeration value="hatchback" />
            </restriction>
          </simpleType>
        </element>
      </sequence>
    </complexType>
  </element>
</schema>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27237607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档