XML Schema: Element that can contain elements or text?

I did some research on this a while ago and the only solution I found was to used the mixed attribute:

<xs:element name="field">
    <xs:complexType mixed="true">
                <xs:element ref="subfield" minOccurs="0" maxOccurs="unbounded" />
        <xs:attribute name="name" type="xs:string" />

This sadly also allows

<field name="test_field_0">
    Some text I'm sure you don't want.
    <subfield>Some text.</subfield>
    More text you don't want.

Hopefully someone will give a better answer.

Leave a Comment