How to define identical elements in DTD with different parent elements?

Let's say I have the following XML:

<data>
  <authors>
    <author>
      <name>
        <first_name>Stephen</first_name>
        <last_name>Baxter</last_name>
      </name>
    </author>
    <author>
      <name>
        <first_name>Joe</first_name>
        <last_name>Haldeman</last_name>
      </name>
    <author>
  </authors>
  <books>
    <book>
      <name>The Time Ships</name>
    </book>
    <book>
      <name>The Forever War</name>
    <book>
  </books>
</data>

In my DTD, how would I explain that the "name" element is used for both authors and books and can have different child elements - like this?

<!ELEMENT name (#PCDATA|first_name,last_name)>
+3
source share
1 answer

Since your element nameis mixed content (both child elements or #PCDATA), you will have to change the element declaration to this:

<!ELEMENT name (#PCDATA|first_name|last_name)*>

This means that you will need to use something other than a DTD to ensure that it namecontains #PCDATAeither one first_namefollowed by one last_name.

+4
source

All Articles