---
title: "XML Student document and its DTD"
subject: "Web Technology"
chapter: 7
key: "semester_7/web_technology:xml-student-dtd"
source: https://www.bctengineer.com/q/semester_7/web_technology/xml-student-dtd
site: BCT Engineering
---

# XML Student document and its DTD

Web Technology · Chapter 7: Information representation and sharing – XML

- Asked in: 2074 Asoj, 2+8 marks
- Video: [XML DTD(Document Type Definition) example programs](https://www.youtube.com/watch?v=s0bqFIdY_pQ) — Biabani Study Tutorials
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/web_technology/xml-student-dtd
- Whole chapter: https://www.bctengineer.com/md/semester_7/web_technology/chapter-7

## Question

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.

## 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.

## Answer

#### 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
<?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`)
```xml
<!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
- `students` is the root and must contain one or more `student` elements (`+`).
- Each `student` must contain `name`, `address`, `phone` and `email`, in that order.
- `name` must contain `firstname` followed by `lastname`.
- `(#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).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How does the XML link to an external DTD file?
   A. <?xml-dtd student.dtd?>
   B. <!DOCTYPE students SYSTEM "student.dtd">
   C. <!ATTLIST students>
   D. <!ELEMENT students SYSTEM>
   Answer: B. DOCTYPE with SYSTEM names the external DTD. (Key point: External DTD link)

2. What does (#PCDATA) mean?
   A. The element holds only text
   B. The element is optional
   C. The element holds child elements only
   D. The element has attributes
   Answer: A. #PCDATA declares text-only content. (Key point: PCDATA)

3. What does <!ELEMENT student (name, address, phone, email)> require?
   A. Zero or more
   B. Any order
   C. Any one of them
   D. Those four children in that order
   Answer: D. A comma is sequence, so they must appear in order. (Key point: Order in student)

## Close variants set in other exams

- [XML and DTD; Teacher XML document](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Axml-teacher-dtd) — Web Technology, chapter 7, asked 2×

## Related in Web Technology

- [Well formed XML and DTD example](https://www.bctengineer.com/question.md?key=semester_7%2Fweb_technology%3Awell-formed-xml-dtd-example) — Web Technology, chapter 7
