- Asked 2/4
- 2074 Asoj · 2+8 marks
XML Student document and its DTD
Short answer
XML is a W3C markup language for exchanging structured data with user-defined tags. A well-formed student XML has root students, student elements containing name (firstname, lastname), address, phone, email. DTD: students (student+), student (name, address, phone, email), name (firstname, lastname), all #PCDATA.
Define XML? Design well formed XML document for "Student". Student should have data such as Name, Address, Phone and Email. Name should contain FirstName and LastName. Also write the DTD (Document Type Definition) for your XML document.
XML
XML (eXtensible Markup Language) is a W3C markup language for describing and exchanging structured data. Tags are defined by the user, it is self-descriptive, platform independent and strict about syntax. It stores data; it does not decide how data is displayed.
Well-formed XML document for "Student" (file student.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE students SYSTEM "student.dtd">
<students>
<student>
<name>
<firstname>Anil</firstname>
<lastname>Thapa</lastname>
</name>
<address>Bhaktapur, Nepal</address>
<phone>9801234567</phone>
<email>anil.thapa@example.com</email>
</student>
<student>
<name>
<firstname>Mina</firstname>
<lastname>Gurung</lastname>
</name>
<address>Pokhara, Nepal</address>
<phone>9812345678</phone>
<email>mina.gurung@example.com</email>
</student>
</students>
DTD for the document (file student.dtd)
<!ELEMENT students (student+)>
<!ELEMENT student (name, address, phone, email)>
<!ELEMENT name (firstname, lastname)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>
Explanation
studentsis the root and must contain one or morestudentelements (+).- Each
studentmust containname,address,phoneandemail, in that order. namemust containfirstnamefollowed bylastname.(#PCDATA)means the element holds only text.<!DOCTYPE students SYSTEM "student.dtd">links the XML to its external DTD. The DTD can alternatively be placed inside the XML in square brackets[ ... ]as an internal subset.
The document is well-formed (one root, proper nesting and closing, case consistent) and valid (it follows the DTD).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- XML and DTD; Teacher XML document · Web Technology, chapter 7 · asked 2×
- Well formed XML and DTD example · Web Technology, chapter 7