'Allowing 2 date types for an attribute in an XML schema
I have written an XML schema and one of the elements is date. Below is the section of the schema that defines date
<xs:element name="temporal">
<!--start date and end date-->
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="date">
<xs:complexType>
<xs:attribute name ="date" type ="xs:date" use="required"/>
<xs:attribute name="dateType" type="xs:string" use="required"/>
<xs:attribute name="dateFormat" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
For the attribute <xs:attribute name ="date" type ="xs:date" use="required"/>
I want to be able to have either type = "xs:date" or type = "xs:gYear" as some collections do not contain full YYYY-MM-DD formats. I attempted doing:
<xs:element name="date">
<xs:simpleType>
<xs:union memberTypes="xs:date xs:gYear" />
</xs:simpleType>
</xs:element>
but this did not work and when I exported the excel form the YYYY date was stored as 1905-02-04. I do not really know if it is possible to have an "or" option with xml schemas? or a solution that allows the option of the two date types without having to have two separate elements?
Any advice or solutions would be helpful
Solution 1:[1]
I think you want
<xs:simpleType name="date-or-gYear">
<xs:union memberTypes="xs:date xs:gYear" />
</xs:simpleType>
and then
<xs:attribute name="date" type ="date-or-gYear" use="required"/>
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 | Michael Kay |
