简体   繁体   English

XML行的XSD模式中的限制?

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

I have this line of code 我有这行代码

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

I want to put an restriction on "myvalue" that it should be between -50 and 50. I have tried many options but i don't know how to use extension and restriction toghether. 我想对“ myvalue”设置一个限制,使其应在-50到50之间。我尝试了很多选择,但我不知道如何一起使用扩展和限制。 Can someone answer please? 有人可以回答吗?

You will need both an extension (since you have the attribute id ) and a restriction (since you have the constraint on the content of floatOutput ). 您将同时需要扩展名(因为您具有属性id )和限制(因为您对floatOutput的内容有约束)。 One approach that I know of is to create a simple type with the constraint and then extend this type with the attribute. 我知道的一种方法是使用约束创建简单类型,然后使用属性扩展该类型。 So something like the following. 所以像下面这样。

<?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