Question

I'm looking for a DTD which would make the first XML document valid and the second invalid, if it's possible.

First XML:

<A>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <D>bla</D>
        <D>bla</D>
    </B>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <D>bla</D>
    </B>
</A>

Second XML:

<A>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <C>bla</C>
        <D>bla</D>
        <D>bla</D>
    </B>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <D>bla</D>
    </B>
</A>

I've got this one, but it does not exclude the second:

<!DOCTYPE A [
<!ELEMENT A (B+)>
<!ELEMENT B (C|D)+>
<!ELEMENT C (#PCDATA)>
<!ELEMENT D (#PCDATA)>
]}

No correct solution

OTHER TIPS

It depends on what you want to accomplish semantically. Often, thinking in terms of the application domain - rather than completely opaque As Bs and Cs - clarifies requirements. Here, one can only guess at the real pattern to be captured. For instance, this would answer your question, but would it address what you really need?

<!ELEMENT A (B+)>
<!ELEMENT B (C,D+)+>
<!ELEMENT C (#PCDATA)>
<!ELEMENT D (#PCDATA)>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top