繁体   English   中英

XML行的XSD模式中的限制?

[英]restriction in XSD schema for an XML line?

我有这行代码

<floatOutput id="2">myValue</floatOutput>

我想对“ myvalue”设置一个限制,使其应在-50到50之间。我尝试了很多选择,但我不知道如何一起使用扩展和限制。 有人可以回答吗?

您将同时需要扩展名(因为您具有属性id )和限制(因为您对floatOutput的内容有约束)。 我知道的一种方法是使用约束创建简单类型,然后使用属性扩展该类型。 所以像下面这样。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:simpleType name="floatOutputType">  
      <xs:restriction base="xs:integer">  
          <xs:minInclusive value="-50"/>  
          <xs:maxInclusive value="50"/>  
      </xs:restriction>  
  </xs:simpleType>

  <xs:element name="floatOutput">  
    <xs:complexType>  
      <xs:simpleContent>  
        <xs:extension base="floatOutputType">  
          <xs:attribute name="id" type="xs:byte" use="required"/>  
        </xs:extension>  
      </xs:simpleContent>  
    </xs:complexType>  
  </xs:element>
</xs:schema>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM