XSD 中的验证属性

Validation attribute in 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: 'price' 的内容必须匹配 (annotation?, (simpleType | ComplexType)?, (unique | Key | Keyref))).发现问题始于:属性。*

感谢您的帮助。

你想定义一个 "complex type with simple content",像这样:

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