Reputation: 1422
How do I an XSD date value which is optional? Is there a way I could escape from using nillable?
For instance, both
<element attribute="attribute">optional-value</element>
<element attribute="attribute"/>
are valid types, where "optional-value" must be defined as an xsd:date type.
Upvotes: 0
Views: 1432
Reputation: 21658
Yes, but not with something that tools like:
XSD:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="EmptyDate">
<xsd:attribute name="attribute" type="xsd:string" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="EmptyDate">
<xsd:union memberTypes="xsd:date emptyString"/>
</xsd:simpleType>
<xsd:simpleType name="emptyString">
<xsd:restriction base="xsd:string">
<xsd:length value="0"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
Invalid XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attribute="attribute1" xmlns="http://tempuri.org/XMLSchema.xsd"> </root>
Valid XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attribute="attribute1" xmlns="http://tempuri.org/XMLSchema.xsd"/>
Upvotes: 3