I've been given the following DTD:
<!ELEMENT book (title, author+, section+)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT section (title, (p | figure | section)* )>
<!ATTLIST section
id ID #IMPLIED
difficulty CDATA #IMPLIED>
<!ELEMENT p (#PCDATA)>
<!ELEMENT figure (title, image)>
<!ATTLIST figure
width CDATA #REQUIRED
height CDATA #REQUIRED >
<!ELEMENT image EMPTY>
<!ATTLIST image
source CDATA #REQUIRED >
and I've been asked:
This DTD is recursive! How does the recursion end?
Ehm... I don't understand why is it recursive? Th only thing that seams to be recursive is the presence of 0 or more section(s).
This DTD is recursive!
I wouldn't say that the DTD is recursive; I would say that the content model for section is recursive because it allows zero or more child section elements.
How does the recursion end?
The recursion ends, in the XML instance, when a section does not contain a child section. Since the child section element is not required, it's not forcing some sort of runaway recursion where you'd never get your instance to validate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With