如何在 xsd 中定义特定数字? [英] How to define a specific number in xsd?

查看:42
本文介绍了如何在 xsd 中定义特定数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究具有该规范的 xsd 规范(用于简单游戏;)):

i am working on an xsd-specification (for a simple game ;) ) which has that specification:

我有一个带有属性 number 的 Elem players,它表示玩家的数量(1 和 4 之间的数字).作为子元素,它包含零到四个 screenname 元素的元素.这些元素具有玩家昵称文本内容和属性,表示游戏结束编号(1 和 4 之间的数字).

I have an Elem players with an attribute number, which indicates the number of the players(a num between 1 and 4). As childelems, it contains elems of zero to four screenname elements. These elements have player screenname text content and attribute, which indicates the end of the game number (a number between 1 and 4).

我的大问题是 xsd 中典型的屏幕名称和间隔?那么该怎么做呢?

My big problems are the screenname and the Intervall in a typ in xsd? So how to do that?

提前问候和感谢

推荐答案

我认为你是这样描述的:

This is what I think you're describing:

<players number="2">
    <screenname endofgame="3">player screenname text content</screenname>
</players>

这将是一个自动生成的 XSD:

This would be an automatically generated XSD:

<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="players">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="screenname">
          <xsd:complexType>
            <xsd:simpleContent>
              <xsd:extension base="xsd:string">
                <xsd:attribute name="endofgame" type="xsd:unsignedByte" use="required" />
              </xsd:extension>
            </xsd:simpleContent>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="number" type="xsd:unsignedByte" use="required" />
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

这将是一个带有额外约束的约束,如下所述:1 到 4 之间的 num0 到 4 个屏幕名称元素.通过查看之前/之后,您应该了解哪个是哪个.

This would be one with additional constraints, as described: a num between 1 and 4 and zero to four screenname elements. By looking at before/after, you should understand which one is which.

<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="players">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="screenname" minOccurs="0" maxOccurs="4">
          <xsd:complexType>
            <xsd:simpleContent>
              <xsd:extension base="xsd:string">
                <xsd:attribute name="endofgame" type="Int1to4" use="required" />
              </xsd:extension>
            </xsd:simpleContent>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="number" type="Int1to4" use="required" />
    </xsd:complexType>
  </xsd:element>
  <xsd:simpleType name="Int1to4">
    <xsd:restriction base="xsd:int">
      <xsd:minInclusive value="1"/>
      <xsd:maxInclusive value="4"/>
    </xsd:restriction>  
  </xsd:simpleType> 
</xsd:schema>

这篇关于如何在 xsd 中定义特定数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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