How can I reuse a complex type in XSD for multiple elements?
Asked Answered
F

1

5

I have been entirely unable to find any information on this, possibly due to me not having the terminology down. What I want to do is create a template element for currency, which I already have, and use it in two places under two different names (ie. currentBalance and maxBalance).

My current format of this template is:

<xsd:element name="currency">
    <xsd:complexType>
        <xsd:simpleContent>
            <xsd:extension base="xsd:double">
                <xsd:attribute ref="currencyCode" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:element>
Fort answered 20/3, 2017 at 2:36 Comment(0)
L
11

Simply globally define and name the complex type you wish to use,

  <xsd:complexType name="currency">
    <xsd:simpleContent>
      <xsd:extension base="xsd:double">
        <xsd:attribute ref="currencyCode" />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>

then reference it where needed:

  <xsd:element name="currentBalance" type="currency"/>
  <xsd:element name="maxBalance" type="currency"/>
Levinson answered 20/3, 2017 at 3:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.