Can I used a arbitrary defined DTD to generate all possible XML templates?

Roseanne Zhang

The answer is NO unless it is an extreme trivial case. See the really trivial DTD bellow. We already have 4 possible "templates". Here we assume templates is the right word here. I use one line for each XML file for easy listing. For a little less trivial DTD, it is easy to imagine that all the combination and permutation will cause an exponential explosion. I don't think you want the result, let alone having the space to store the result or writing an application to use that result.

Trivial DTD file

  <!ELEMENT person (name,age,sex)>    
  <!ELEMENT name (#PCDATA)>    
  <!ELEMENT age (#PCDATA)>    
  <!ELEMENT sex (#PCDATA)>
Four possible XML "templates"
  1. <name>some_name</name>
  2. <age>some_number</age>
  3. <sex>one_of_the_two</sex>
  4. <person><name>some_name</name><age>some_number</age><sex>one_of_the_two</sex></person>

If you don't believe all four are valid against the DTD, try to validate them by yourself .