user618677
user618677

Reputation: 5069

DTD's Mixed content model

Say I have something like this

       <offor>Ubuntu Juju is all that you need 
      <charm Id="lisp" \>.</offor><offor>This one is the name thing</offor>

This is my DTD

       <!ELEMENT offor (#PCDATA, charm?) >
      <!ELEMENT charm EMPTY>
      <!ATTLIST id ID #REQUIRED>

Could someone assist me here? My DTD is not working

Upvotes: 1

Views: 2420

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52858

There are a few things wrong with both your XML and your DTD:

  1. You don't have a root element. I added <doc> in my example below.

  2. You used a backslash (\) instead of a forward slash (/) when you closed charm.

  3. When you have mixed content, you can't specify the order of #PCDATA and the child elements using ,. You have to use | (or) and an asterisk (*).

  4. In your ATTLIST declaration, you forgot to add the name of the element the attribute(s) are declared for.

  5. The Id attribute in the XML does not match the case of the attribute name id in the DTD.

Here's an example of an updated XML and DTD. The DTD is in the internal subset, but would work just as well if used as an external DTD.

<!DOCTYPE doc [
<!ELEMENT doc (offor+)>
<!ELEMENT offor (#PCDATA|charm)* >
<!ELEMENT charm EMPTY>
<!ATTLIST charm 
          id ID #REQUIRED>
]>
<doc>
  <offor>Ubuntu Juju is all that you need 
    <charm id="lisp"/>.</offor><offor>This one is the name thing</offor>
</doc>

Upvotes: 6

Related Questions