Search code examples
xmldtdxml-validation

XML DTD "Content of element type must match "null"


First time working with DTD. I've looked at some examples and I'm not too sure where I'm going wrong. When I validate my XML an error that keeps coming up is

The content of element type "stanza" must match 'null'.

Here is a chunk of my XML with my DTD:

<!DOCTYPE Week4 [
<!ELEMENT Week4 (poems,videos)>
<!ELEMENT poems (poem1,poem2,poem3,poem4)>
<!ELEMENT poem1 (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT stanza (#PCDATA)>
<!ELEMENT line (#PCDATA)>
]>
<Week4>
<poems>
    <poem1>
    <author>Edwin Arlington Robinson</author>
    <title>Richard Cory</title>
    <stanza>
        <line>Whenever Richard Cory went down town,</line>
        <line>We people on the pavement looked at him:</line>
        <line>He was a gentleman from sole to crown,</line>
        <line>Clean favored, and imperially slim.</line>
    </stanza>

Solution

  • Change

    <!ELEMENT stanza (#PCDATA)>
    

    to

    <!ELEMENT stanza (line*)>
    

    to allow stanza to consist of zero or more line elements.