How can I write an XSD for the following XML?
<A></A>
<B></B>
<C></C>
<D></D>
<E></E>
<E></E>
A,B,C,D just have zero or one. And they don't have sequence. It could be D,C,B,A. And in the very end, there are one or more E element(s).
I have tried multiple ways, but can't get it done.
You're blocked by a non-orthogonality of XML Schema. You'd think that the following should work:
However, it does not. XSD's
xs:all
construct is a second-class citizen; it cannot appear in axs:sequence
.Recommendation: Drop the "any order" allowance from your requirements:
Allowing any order of elements ends up being less important in practice than in theory, especially given non-orthogonality such as the above and the potential for clashes with Unique Particle Attribution.