8
votes

I Want to create a DTD schema for this xml document:

<root>

    <student>
        <name>
            <firstname>S1</firstname>
            <lastname>S2</lastname>
        </name>
    </student>

    <course>
        <name>CS101</name>
    </course>

</root>

as you can see , the element name in the course contains plain text ,but the element name in the student is complex type ( first-name, last-name ). The following is the DTD:

<!ELEMENT root (course|student)*>

<!ELEMENT student (name)>
<!ELEMENT name (lastname|firstname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>

<!ELEMENT course (name)>

When I want to validate it , I get an error because the course's name has different structure then the student's name .

My Question:

  • how can I make a work-around solution for this situation without changing the name of element name using DTD not xml schema .

Thanks.

1

1 Answers

10
votes

Sorry! That's one of the major limitations of DTD: a given element name always has the same content model.

About all you can do is give up on full validation for that particular element, and allow all possible contents:

<!ELEMENT name (#PCDATA|lastname|firstname)*>