Matthias M
Matthias M

Reputation: 135

Use an element twice in one XSD?

I have an XML Schema with a lot of elements. One element, patient, has a lot of child elements. This patient element is a child of the root element and of another element. Do I have to copy the whole code of the element patient twice in that document or is there an copy link element or something else?

Upvotes: 1

Views: 817

Answers (1)

kjhughes
kjhughes

Reputation: 111726

You've described a use of xs:element/@ref:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <!-- First reference to patient -->
        <xs:element ref="patient"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- Additional references to patient -->

  <!-- Reused definition of patient -->
  <xs:element name="patient">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:string"/>
        <xs:element name="birthdate" type="xs:date"/>
        <xs:element name="weight" type="xs:decimal"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

Upvotes: 2

Related Questions