开发者

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 na开发者_JAVA技巧me 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


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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜