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:
You don't have a root element. I added
<doc>
in my example below.You used a backslash (
\
) instead of a forward slash (/
) when you closedcharm
.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 (*
).In your
ATTLIST
declaration, you forgot to add the name of the element the attribute(s) are declared for.The
Id
attribute in the XML does not match the case of the attribute nameid
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>
精彩评论