Internal and External DTD Declaration

Estudies4you
Internal And External Entities in DTD

Internal and External DTD Declaration

You can declare DTD internally or as an external file
Internal Declaration
External Declaration

Internal Declaration
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Raju</to>
<from>Ravi</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
!DOCTYPE note defines that the root element of this document is note.
!ELEMENT note defines that the note element contains four elements: "to,from,heading,body". !ELEMENT to defines the to element to be of the type "#PCDATA".
!ELEMENT from defines the from element to be of the type "#PCDATA".
!ELEMENT heading defines the heading element to be of the type "#PCDATA".
!ELEMENT body defines the body element to be of the type "#PCDATA".

External Declaraton
If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax:
<!DOCTYPE root-element SYSTEM "filename">
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Raju</to>
<from>Ravi</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

And this is the file "note.dtd" which contains the DTD:
<!ELEMENT note (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>

<!ELEMENT body (#PCDATA)>

Internal And External Entities in DTD 

Internal Entities
External Entities
Internal defined as Entities that located local system
It can defined as an entity which is located in remote system
Syntax:
<! ENTITY entity_ name Entity _value>
Syntax:
<! ENTITY entity_name SYSTEM "Entity_path">
DTD Example:
<!ENTITY author "Uttam K Roy">
<IENTITY copyrights "OxfordUniversity">
DTD Example:
<!ENTITY author SYSTEM http ://loca I host: 8080/exa mpple/Exa mple.dtd >
<!ENTITY copyrights SYSTEM http://localhost:8080/exampple/Example.dtd>
XML Example:
<editor>&author; & copyrights;</editor>
XML Example:
<editor>&author; & copyrights;</editor>



To Top