Free degree-level computing lessons for careful independent study.

Degree Level Programmes · Search, data management and analytics · Lesson 4

XML, Markup, Validation and Document Trees

Develop XML as a semi-structured representation for documents and records, including elements, attributes, document trees, validation, DTD and schema design.

Lesson overview

Develop XML as a semi-structured representation for documents and records, including elements, attributes, document trees, validation, DTD and schema design.

CourseInformation Storage and Retrieval
Topic strandSemi-structured data
Assessment styleWorked scenario, applied task and digital exam practice
EvidenceDefinitions, representation, method, result and interpretation

Starter

Write down the user need, the data being stored or searched, and the decision the system has to support. Then predict which representation, index, query method or governance control will matter most in this lesson.

Learning objectives

  • Read XML as a labelled tree of elements and attributes.
  • Explain the purpose of validation using a DTD or XML schema.
  • Design a small XML record for searchable document metadata.

Learning outcomes

  • Students can read XML as a labelled tree of elements and attributes.
  • Students can explain the purpose of validation using a DTD or XML schema.
  • Students can design a small XML record for searchable document metadata.

Key vocabulary, acronyms and terminology

XML
Extensible Markup Language, a text format for labelled hierarchical data.
element
A tagged XML component that may contain text or child elements.
attribute
A name-value pair stored inside a start tag.
document tree
The hierarchical structure formed by nested XML elements.
DTD
A Document Type Definition describing allowed XML structure.
schema
A formal specification of permitted elements, attributes and types.

Detailed teaching notes

Core concept

XML is semi-structured because records carry explicit labels and hierarchy, but different document types can still vary. It is especially useful when documents need both human-readable content and machine-readable structure.

Representation choice

An XML article record can store title, author, abstract and keywords in a document tree. The tree shape is important: a keyword inside one article is not the same as a keyword floating outside the article record.

Method and reasoning

Design XML from the retrieval questions. If users search by author, date and topic, those values should appear in predictable elements or attributes and the schema should validate their presence and type.

Risk and limitation

Markup is not a substitute for modelling. Poor XML can be verbose, inconsistent and hard to query if element names change or if meaningful data is hidden in uncontrolled text.

Degree-level deep dive

XML is a tree, not decoration

XML markup has retrieval value only when elements and attributes carry stable meaning. The nested document tree determines context, so a keyword inside one article is different from an unscoped keyword elsewhere.

Validation protects later search

A DTD or schema is not only a syntax exercise. It protects required metadata, element names and allowed structures so the indexer can extract fields consistently across a collection.

What excellent work shows

A strong answer distinguishes well-formed XML from valid XML, sketches the element hierarchy, and explains how validation failures produce practical retrieval problems such as missing author filters or unreliable date browsing.

Concrete example to study

Article metadata record

<article id="A17">
  <title>Search logs and learning</title>
  <author id="P4">M. Evans</author>
  <date>2026-03-12</date>
  <keyword>information retrieval</keyword>
</article>

Reasoning

  1. The root element is article, and title, author, date and keyword are children in the document tree.
  2. A validation rule can require exactly one title, at least one author and a date in a controlled format.
  3. The indexer can extract title, author and keyword fields reliably only if the markup is consistent.
Reveal takeaway

The point of XML validation is retrieval quality: inconsistent tags create inconsistent searchable fields.

Worked example

Scenario

A publisher sends article metadata as XML and the archive must validate required fields.

Worked solution

  1. Identify the root element, such as article.
  2. Place title, author, date and abstract as child elements so they form a clear document tree.
  3. Use a DTD or schema rule to require title and at least one author.
  4. Reject or flag records that do not match the declared schema before indexing.
Reveal model result

Validation protects retrieval quality. If required metadata is missing or inconsistently labelled, the search index will contain gaps and filters such as author or date will be unreliable.

Applied retrieval task

Create an XML metadata record for a podcast episode.

Deliverables

  1. Write a small XML example with title, host, date, duration and topics.
  2. Sketch the document tree implied by the nesting.
  3. Write two validation rules that protect retrieval.

Success checks

  • The XML has one clear root element.
  • Validation rules match later search needs.

Common misconception

Students sometimes think well-formed XML and valid XML are the same. Well-formed means the syntax is legal; valid means it also conforms to a DTD or schema.

Quick checks

1. In this lesson, why does XML matter?

2. Which answer best shows degree-level understanding of xml, markup, validation and document trees?

Digital exam practice

Example exam task

A digital archive receives XML records for research reports, but some records omit publication date and use inconsistent tags for author names. In your answer, define the relevant objects or data structures, use course-specific vocabulary, show the method rather than only the result, and finish with a decision about the storage or retrieval system.

Notation and technical toolkit

<record>XML element Use tags to mark the boundary of a structured component.
<!ELEMENT ...>DTD declaration Use to describe allowed children in a simple validation language.
xs:schemaXML Schema document Use when typed validation is needed.

What a good answer is expected to show

A strong answer for XML, Markup, Validation and Document Trees the answer should describe the document tree, explain validation with DTD or schema, and connect consistent markup to later retrieval filters. It should connect the formal or technical representation to the user's information need instead of listing terms without using them.

How to solve it

  1. Identify the required metadata fields from retrieval needs.
  2. Represent the record as a nested XML document tree.
  3. Specify validation using a DTD or schema.
  4. Explain how validation failures affect indexing and browsing.

Model answer

Reveal model answer

I would model each report as one XML document rooted at <report>, with child elements for title, authors, date, abstract and keywords. A DTD or XML schema should require date and at least one author, and should standardise the author element name. Once records validate, the indexer can reliably extract date and author fields for filters. Without validation, two visually similar records may be indexed differently, causing missing or misleading search results.

Practise next

  1. Write a DTD-style rule for an article with title, one or more authors and optional keywords.
  2. Explain why XML hierarchy matters when extracting metadata for a search index.

Self-marking criteria

  • Defines the scenario objects, data forms or system components before solving.
  • Uses the lesson vocabulary accurately and in context.
  • Shows a clear method with enough working for a marker to follow.
  • Connects the result back to retrieval, storage, analytics or governance.
  • States a limitation, trade-off or quality risk rather than presenting the answer as absolute.

Extension

Compare an XML article record with a JSON version and discuss which is easier to validate and transform.

Study route

Save a short worked answer from this lesson using this pattern: define the need or data, choose the representation, show the method, state the result and interpret the implication for the system.

Next lesson: Multimedia Representation: Images, Audio and Video.