MC Emperor
MC Emperor

Reputation: 23027

How to define a child element which only comes as first inside a parent element?

I want to create a document type definition for an XML document.

I have the XML document in the following form:

<parent>
    <first>Some PCDATA</first>
    <a>The elements aye...</a>
    <c>see</c>
    <b>and bee</b>
    <c>can occur in random order</c>
    <a>and with a random frequency</a>
    <last>Some PCDATA</last>
</parent>

I just want element first to be the first element (and only occurring once), the element last to be the last child element (and only occurring once), and elements a, b and c zero or more times occurring in a mixed order.

Can I achieve that? If yes, how? If not, what may be a workaround which comes close to this?

Upvotes: 0

Views: 39

Answers (1)

collapsar
collapsar

Reputation: 17238

this should work:

<!DOCTYPE parent [
    <!ELEMENT parent (first, (a|b|c)*, last) >
    <!ELEMENT first #PCDATA >
    <!ELEMENT a ANY >
    <!ELEMENT b ANY >
    <!ELEMENT c ANY >
    <!ELEMENT last #PCDATA >
]>

Upvotes: 1

Related Questions