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:
name
using DTD not xml schema .
Thanks.
A Document Type Definition (DTD) describes the tree structure of a document and something about its data. It is a set of markup affirmations that actually define a type of document for the SGML family, like GML, SGML, HTML, XML. A DTD can be declared inside an XML document as inline or as an external recommendation.
The critical difference between DTDs and XML Schema is that XML Schema utilize an XML-based syntax, whereas DTDs have a unique syntax held over from SGML DTDs. Although DTDs are often criticized because of this need to learn a new syntax, the syntax itself is quite terse.
The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference.
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)*>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With