2015-09-28 102 views
1

我试图将XSD中的限制添加到复杂类型元素。我尝试使用minInclusive value =“0.00034”和maxInclusive value =“99”在我使用XML Notepad 2007验证XML文件时添加边界。我搜索了档案并且难以使用添加位置的语法限制。任何帮助表示赞赏。如何限制元素内容并在XSD中同时定义属性

<xsd:element name="R-value"> 
    <xsd:annotation> 
     <xsd:documentation>Resistance of material</xsd:documentation> 
    </xsd:annotation> 
    <xsd:complexType> 
     <xsd:simpleContent> 
      <xsd:extension base="xsd:decimal"> 
       <xsd:attribute name="unit" type="resistanceUnitEnum" use="required"/> 
      </xsd:extension> 
     </xsd:simpleContent> 
    </xsd:complexType> 
</xsd:element> 

回答

0

定义类型涵盖你的限制,并扩展该类型在你的属性添加:

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

    <xsd:simpleType name="R-value-content-type"> 
    <xsd:restriction base="xsd:decimal"> 
     <xsd:minInclusive value="0.00034"/> 
     <xsd:maxInclusive value="99"/> 
    </xsd:restriction> 
    </xsd:simpleType> 

    <xsd:element name="R-value"> 
    <xsd:annotation> 
     <xsd:documentation>Resistance of material</xsd:documentation> 
    </xsd:annotation> 
    <xsd:complexType> 
     <xsd:simpleContent> 
     <xsd:extension base="R-value-content-type"> 
      <xsd:attribute name="unit" use="required"/> 
     </xsd:extension> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    </xsd:element> 
</xsd:schema>