Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why this DTD is recursive?

Tags:

xml

dtd

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).

like image 609
bog Avatar asked May 09 '26 03:05

bog


1 Answers

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.

like image 59
Daniel Haley Avatar answered May 14 '26 18:05

Daniel Haley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!