'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?
Solution 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kjhughes |
