DI-322 Web Technologies Lecture 05: XML, XHTML, mobile markup, XSL and XML queries
DI-322 Web Technologies
0% Completed

Lecture 05: XML, XHTML, mobile markup, XSL and XML queries

Outcomes and readiness

You can test XML well-formedness, compare HTML and XHTML syntax, explain WML/XHTML mobile profiles historically, transform XML with XSLT, and select nodes with XPath/XQuery. Readiness: identify start tags, end tags, attributes, and nesting in HTML.

Motivating problem

A department must exchange course data between different systems. A structured format needs explicit nesting and machine-checkable syntax. XML supplies a syntax for documents; a schema can add vocabulary rules; transformations and queries operate on the resulting tree.

<?xml version="1.0" encoding="UTF-8"?>
<course code="DI-322">
  <title>Web Technologies</title>
  <credits>3</credits>
</course>

Core distinctions

XML is case-sensitive, requires one document element, quoted attribute values, and properly nested/closed elements. Well-formed means the XML syntax rules are satisfied; valid means it also conforms to a chosen DTD or schema. XHTML applies XML syntax to an HTML vocabulary. The source spelling XHTM MP is preserved in the ledger; this lesson provisionally interprets it as XHTML Mobile Profile, a historical mobile-web profile. WML is likewise historical and targeted early constrained wireless devices. Modern responsive HTML/CSS is the practical default, but the historical topics remain required.

Worked XPath and XSLT idea

For the document above, XPath /course/title/text() selects Web Technologies; /course/@code selects DI-322. XSLT can match course and emit HTML. XPath selects; XSLT transforms; XQuery can construct and query across XML collections.

Faded example

Repair <Course code=DI-322><title>Web</Course>.

  • Hint 1: attribute values need quotes.
  • Hint 2: element names are case-sensitive and nesting must close in reverse order.
  • Solution: <course code="DI-322"><title>Web</title></course>.

Common mistakes

  • An .xml extension does not prove well-formedness or validity.
  • XHTML served as HTML is parsed as HTML; media type affects processing.
  • XPath uses / for paths; it is not a SQL table query.

Practical – DI322-LAB05

Create courses.xml with three courses. Write XPath expressions for all titles, the course with code DI-322, and courses with credits greater than 2. Then draft an XSLT template that outputs a list. Record whether your tool executed XPath/XSLT or whether the result is a reasoned trace.

Independent check

  • Q1: Well-formed versus valid? Answer: syntax only versus syntax plus schema/DTD conformance.
  • Q2: Why close <br /> in XHTML? Answer: XML syntax requires an empty element to be explicitly closed.
  • Q3: XHTM MP handling? Answer: preserve source wording; likely XHTML Mobile Profile, marked provisional.
  • Q4: WML status in this course? Answer: required historical topic, not the modern default.
  • Q5: XSLT’s job? Answer: transform XML trees into another result.
  • Q6: XPath /course/@code selects what? Answer: the code attribute of the root course.

Homework – DI322-A05-H1

Design XML for a course, two lessons, and outcomes; include one namespace. Supply three XPath queries and a short XSLT output sketch. Rubric: well-formed XML 3, model 2, namespace 1, queries 2, transformation reasoning 2.

Revision

XML syntax -> optional validation -> query/transform. Historical mobile profiles solved constraints that responsive standards now address differently.