Examples of DTD and xml for A.T.I.T By Dr. PERI SASTRY
A external dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT supplier_table (supplier_data+)>
<!ELEMENT supplier_data (sup_no, sup_name,sup_address, telephone*)>
<!ELEMENT sup_no (#PCDATA)>
<!ELEMENT sup_name (#PCDATA)>
<!ELEMENT sup_address (street,city, pin)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT pin (#PCDATA)>
<!ELEMENT telephone (#PCDATA)>
Xml document conforming to the above dtd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE supplier_table SYSTEM "ASG2-Supplier.dtd">
<supplier_table>
<supplier_data>
<sup_no>S0012</sup_no>
<sup_name>sastry</sup_name>
<sup_address>
<street>KML</street>
<city>BLR</city>
<pin>034</pin>
</sup_address>
<telephone>553553</telephone>
<telephone>553552</telephone>
</supplier_data>
<supplier_data>
<sup_no>S00123</sup_no>
<sup_name>Sreeni</sup_name>
<sup_address>
<street>BSK</street>
<city>BLR</city>
<pin>095</pin>
</sup_address>
</supplier_data>
<supplier_data>
<sup_no>X0023</sup_no>
<sup_name>Xavier</sup_name>
<sup_address>
<street>ECT</street>
<city>BLR</city>
<pin>100</pin>
</sup_address>
<telephone>552222</telephone>
</supplier_data>
</supplier_table>
The special symbols at end of element names in a DTD mean as below:
Symbol / Structure / What it indicates / In briefFollow the name of a child element with a ? / (elementname?) / Indicates that it may appear once or NOT at all in an xml document / Not at all
Or Once
(Zero or one)
Follow the name of a child element with a * / (elementname*) / Indicates that it may NOT appear at all or may appear any number of times in an xml document / Not at all or
As many times as required
(Zero or more)
Follow the name of a child element with a + / (elementname+) / Indicates that it MUST appear at least once or may appear any number of times in an xml document / MUST once or
any number of times
( One or more)
Comma and a space or No symbol at end of last element / (elementname, elementname ) / Element must appear once only / must appear once only
If all or some elements are separated with a pipe | character , then they can appear one or more times in any order under the parent element / ( elementname1 | elementname2 | elementname3 ) / Example:
<!ELEMENT answer(choice1 | choice2 | choice3)> / Xml document can have either choice1 or choice2 or choice3 under answer element
B) Example of Internal DTD with xml document for ATIT By Dr. PERI SASTRY
<?xml version = "1.0" ?>
<!DOCTYPE businessletter
[
<!ELEMENT businessletter (from,to,body)>
<!ELEMENT from (name,address,tel)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (street,town,state,pin)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT town (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT pin (#PCDATA)>
<!ELEMENT tel (#PCDATA)>
<!ELEMENT to (name2,address2,tel2)>
<!ELEMENT name2 (#PCDATA)>
<!ELEMENT address2 (street2,town2,state2,pin2)>
<!ELEMENT street2 (#PCDATA)>
<!ELEMENT town2 (#PCDATA)>
<!ELEMENT state2 (#PCDATA)>
<!ELEMENT pin2 (#PCDATA)>
<!ELEMENT tel2 (#PCDATA)>
<!ELEMENT body (paragraph?)>
<!ELEMENT paragraph (#PCDATA | p)*>
<!ELEMENT p (#PCDATA)>
]>
<businessletter>
<from>
<name> Dr Sastry</name>
<address>
<street>
8th Block Koramangala
</street>
<town>
Bangalore
</town>
<state>
Karnataka State
</state>
<pin>
560034
</pin>
</address>
<tel> 555-4321 </tel>
</from>
<to>
<name2> U.B.S.Traders </name2>
<address2>
<street2>
201, MG Road
</street2>
<town2>
Bangalore
</town2>
<state2>
Karnataka
</state2>
<pin2>
560001
</pin2>
</address2>
<tel2>555-1234</tel2>
</to>
<body>
<paragraph>
Dear Sir/Madam
It is our privilage to inform you about out new databse managed with
xml . this new ssytems allows you to reduce the load on your
inventory server by having the client machine perform the work of sorting and filtering the
data. in an
<p> XML </p>
element is machine and human understandable.so plain text
will not be gibberish
Sincerly
Dr Sastry
</paragraph>
</body>
</businessletter>