加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – XSD用于简单包含属性和文本

发布时间:2020-12-16 07:46:07 所属栏目:百科 来源:网络整理
导读:如何验证具有属性的元素的文本长度. 例如: sport code="FB"Football/sport 现在我需要限制代码属性的可能值(如“FB”,“BB”,“TT”) 我还需要限制文本的可能值和长度(“Football”,“BasketBall”,“TableTennis”)以及这些文本的最大长度(“Football”,“
如何验证具有属性的元素的文本长度.
例如:
<sport code="FB">Football</sport>

现在我需要限制代码属性的可能值(如“FB”,“BB”,“TT”)
我还需要限制文本的可能值和长度(“Football”,“BasketBall”,“TableTennis”)以及这些文本的最大长度(“Football”,“TableTennis”)可以20.

我试过了

<complexType name="sport">
  <simpleContent>
    <extension base="string">
        <attribute name="code" type="code" />
    </extension>
  </simpleContent>
</complexType>
<simpleType name="code">
    <restriction base="string">
        <enumeration value="FB" />
        <enumeration value="BB" />
        <enumeration value="TT" />
    </restriction>
</simpleType>

但我无法验证文本“Foolball”的长度(也可能是值)
您能否帮助您了解如何验证代码和文本.
谢谢

我有同样的问题,当我看到有一个接受的答案时,我很有希望.但是,这个答案正是我试过的,但是我得到了一个架构无效的错误.显然,您不能在complexType中限制simpleContent,只能扩展它.此外,您不能在complexType中同时拥有属性和simpleContent.在办公室周围的书籍中搜索示例时,我想出了一个修复程序,我已经适应了这个问题,以防将来有人遇到这个问题:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:sp="http://www.ckhrysze.net/sports/1.0"
            targetNamespace="http://www.ckhrysze.net/sports/1.0"
        >

  <xsd:element name="sports">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="sport" type="sp:sportType" minOccurs="1" maxOccurs="unbounded" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:complexType name="sportType">
    <xsd:simpleContent>
      <xsd:extension base="sp:sportEnumeration">
        <xsd:attribute name="code" type="sp:codeEnumeration" />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>

  <xsd:simpleType name="sportEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Football" />
      <xsd:enumeration value="Basketball" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="codeEnumeration">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="FB" />
      <xsd:enumeration value="BB" />
    </xsd:restriction>
  </xsd:simpleType>

</xsd:schema>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读