Explain DTD (Document Type Definition)
https://www.computersprofessor.com/2016/06/explain-dtd-document-type-definition.html
The XML has neither meaning nor
context without gramer aganist which it
can be validated. The gramer is called a document type definition (DTD). While
constructing XML files we follow set of rules. These rules will be returned
either in the form of DTD (or) XML schema.
The
XML documents that are coming based on common set of DTD (or) schema rules can
be processed easily. Can be merged and compared easily. All programmers of java
web application development use DTD/schema rules given by ‘Sun micro system’
while constructing web XML file. The tag names in XML file becomes pre defined tags
when it is developed based on DTD rules and schema rules.
Elements:-
The XML document is composed of a
number of elements.
The first node of the XML document is
called the root node.
It contains all other nodes of the
document on each XML document must have exactly one root node.
To link XML files with external DTD
file we use < ! doctype- - - - > statement kept in web. XML of web
application development.
<!
Doctype webapp public: “//sunmicrosystem.Inc//DTD web application 2.3
//EN” “http: //java. Sun.com/DTD/webapps
2.3 dtd”>
In
DTD and schema rules of XML the following things will be available.
names of tags
hierarchy of tags.
data type’s of the attribute tag body
values.
users defined entities.
Prepare a student. XML file based on
DTD rules.
DTD Rules:-
1. ‘Students’ must be root element.
2. ‘Students’ allow one (or) more
student.
3. Student must have attribute called
type with one of these values “Regular/part time”.
4.Each student must have these in a
sequence (<SNO>, <SNAME>, <SADD>).
5. <SNO>< <SNAME>, <SADD> tag allow #PCDATA body.
The equalent DTD code is:
Rules. Dtd
<! Element students (student) +
>
<! Element student (sno. Sname, sadd)>
<! Attlist student type
(regula/part time )# Required>.
<! Element sno (# pcdata )>
<! Element sname (#pcdata) >
< ! Element sadd (# pcdata)>
valid XML document:
< ! Doctype student system rules. dtd>
< students>
< students type= “regular”>
< sno> 101 </ sno>
<sname> Raja < / sname>
<sadd > Rjy < / sadd>
</ student>
<student type = “part time” >
< sno>102 < /sno>
<sname> Ramu </sname>
<sadd > TNK < /sadd>
</student>
</students>
Difference between CDATA and PCDATA: when tag body is configured C data
in DTD rules the XML parses will
not expend the entities while reading
body of the tag.
Eg: < msg > 110& gt;15 </
msg>
Configured as CDATA – parser (o/p: 10 >15)
If tag body is configured as PCDATA then the XML passes will expend entity with symbols
while reading the body of the
tag.
< msg > 10> 5 </ msg>
Configured as PCDATA – paresr (o/p:10>5)
