XSD中的验证属性

时间:2015-02-17 08:20:25

标签: xml xsd

我在XSD中遇到问题,我需要在XSD中验证XML,但是我很难声明属性

属性为:

<xs:attribute name='currency' type='xs:string'/>

XML格式的代码:

<price currency="€">30,65</price>

代码XSD:

<xs:element type="xs:string" name="information"/>
<xs:element type="xs:string" name="data"/>
<xs:element type="complexPrice" name="price"/>
<xs:complexType name="complexPrice">
  <xs:attribute name='currency' type='xs:string'/>
</xs:complexType>

这是错误:

S4s-elt-must-match.1:&#39;价格的内容&#39;必须匹配(注释?,(simpleType | ComplexType)?,(唯一|键| Keyref)))。从以下位置找到问题:属性。*

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您想要定义“具有简单内容的复杂类型”,如下所示:

<xs:element name="price">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:decimal">
        <xs:attribute name="currency" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>