开发者

How to define same-named elements in DTD having 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 account for the fact 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)>


Since your name element is mixed content (both child elements or #PCDATA), you're going to have to change your element declaration to this:

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

This means that you are going to have to use something other than DTD to enforce that name contains #PCDATA or one first_name followed by one last_name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜