My question is almost exactly the same as this one, but for a xs:dateTime type rather than a user defined element.
An element in my XML (which I do not create) can l
1 You can declare the element nillable (as suggested by Ben).
2 You can declare a simple type which is a union of xs:dateTime and the empty string. This is easiest to follow if we build it up in stages. First, declare a named simple type whose sole value is the empty string:
Then declare a union type whose members are xs:dateTime and empty-string:
Then use dateTime-or-nothing as the basis for your extension step:
If the reference attribute should occur if and only if the element has no content, then you'll need an XSD 1.1 assertion to that effect (or an ancillary Schematron schema, or ad-hoc validation code at the application layer). XSD content models make it easy to say you must have either a dateTime or a reference, but only if each of those options is represented by a child element.