Introduction to Web Technologies and Architectures · Web Technology

XML (eXtensible Markup Language)

1. Definition

XML (W3C, 1998) is a meta-markup language — a simplified subset of SGML — used to describe, store and transport structured data. Unlike HTML (fixed tags for display), XML lets you invent your own tags that describe the meaning of data.

<?xml version="1.0" encoding="UTF-8"?>
<student roll="101">
  <name>Asha Patil</name>
  <branch>IT</branch>
  <marks semester="6">82</marks>
</student>

XML is not a presentation language: it carries data between systems (web services, config files, feeds, e-commerce), and something else (CSS/XSL, a program) presents it.

2. Key Features

  • Extensible — define your own vocabulary via DTD or XML Schema.
  • Self-describing — tags say what the data is; human-readable.
  • Platform/vendor neutral — plain text, Unicode; any language can parse it.
  • Strict, standardised syntax — one parser behaves everywhere.
  • Separates data from presentation (pair with CSS/XSL for display).
  • Tree (hierarchical) structure — naturally models nested records.

3. Well-Formed vs Valid XML

Well-formed (syntax rules — mandatory):

  1. Exactly one root element.
  2. Every start tag has a matching end tag (or is self-closed ).
  3. Tags properly nested (<b><i></i></b>, never overlapping).
  4. Case-sensitive tag names; attributes quoted; no unescaped < & >.
  5. Comments <!-- --> and PIs <?xml ... ?> written correctly.

Valid = well-formed and conforms to a DTD or XML Schema.

4. Components of an XML Document

Component Example Purpose
Prolog <?xml version="1.0"?> Version, encoding
Root element <library> The single top node
Elements/children <book>…</book> Data structure
Attributes <book year="2020"> Element metadata
Text (PCDATA) Asha Actual content
Entities &lt; &amp; &copy; Special characters
CDATA section <![CDATA[ x < y ]]> Unparsed literal text
Comments/PIs <!-- note --> <?php … ?> Meta information

Namespaces avoid name clashes when mixing vocabularies:

<inv xmlns:item="http://shop.example.com/item">
  <item:product>Pen</item:product>
</inv>

5. Parsing XML

Parser Model Best for
DOM Builds the whole tree in memory; random access Small docs, editing
SAX Event stream (start/end element callbacks); constant memory Large docs, read-only
StAX / lxml / ElementTree Pull-parsing, simpler API Modern apps

6. Advantages and Limitations

Advantages: simple, extensible, hierarchical, human-readable, universally supported, ideal for B2B data exchange (SOAP, RSS, config, Word/Office formats).
Limitations: verbose (large files), slower than binary JSON for JS clients, no built-in display, still needs schema validation for safety.

7. Applications

Web services (SOAP/WSDL), RSS/Atom feeds, configuration files (pom.xml, web.xml, Android layouts), data interchange in e-commerce & banking, e-books (EPUB), Office/CSV replacement, syndication, and as the base of XHTML/SVG/MathML.

8. Exam Points

  • Define XML and explain its features with an example document — 7 marks.
  • Explain well-formed vs valid XML with rules — 7 marks (very frequent).
  • Compare HTML and XML — 5 marks.
  • Explain DTD/Schema validation and DOM vs SAX parsers — 5-7 marks.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Web Technology modules