Free tutorial · 28 lessons

XML Tutorial

XML from the basics to advanced use: syntax, well-formedness, namespaces, validation with DTD, XML Schema, RELAX NG and Schematron, XPath, XSLT and XQuery, parsing in Python, PHP, Java and JavaScript, streaming, XML security (XXE), and real-world formats such as SOAP, RSS, sitemaps, SVG and Office files.

Start learning →

XML Basics

  1. XML Introduction — What XML is, what it's used for today, how it differs from HTML and JSON, and how to read and write it in Python, PHP and Java.
  2. XML Syntax — The XML declaration, the root element, start and end tags, empty elements, attributes, comments and processing instructions.
  3. Elements vs Attributes — When to store data in elements and when in attributes, how to design readable XML, and mixed content.
  4. Well-Formed XML — The rules every XML document must follow, what parsers do with mistakes, and how to read parser error messages.
  5. Escaping, CDATA and Encoding — Predefined entities, character references, CDATA sections, and character encodings such as UTF-8.
  6. XML Namespaces — Why namespaces exist, prefixes and default namespaces, and how to query namespaced XML without getting empty results.
  7. XML History & Versions — Where XML came from, how it grew out of SGML into the W3C standard behind documents, configuration and enterprise integration, the versions of XML, XPath, XSLT, XQuery and XML Schema on one timeline, and which to use today.

Validation

  1. DTD: Document Type Definitions — Declaring elements, attributes and entities in a DTD, validating documents against it, and the limits of DTDs.
  2. XML Schema (XSD) Basics — Writing an XML Schema with elements, simple and complex types, attributes and occurrence rules, and validating against it.
  3. XML Schema: Advanced Types — Restrictions and facets, enumerations and patterns, named and derived types, keys and references, and target namespaces.
  4. RELAX NG and Schematron — RELAX NG as a simpler grammar-based schema language, and Schematron for business rules that grammars can't express.

XPath, XSLT and XQuery

  1. XPath Basics — Selecting nodes with XPath: paths, the // shortcut, attributes, predicates, and the core functions.
  2. XPath Axes and Functions — Axes such as ancestor and following-sibling, string and number functions, position(), and what XPath 2.0 and 3.1 add.
  3. XSLT Basics — Transforming XML with XSLT 1.0: templates, xsl:value-of, xsl:for-each, xsl:if, xsl:sort, and running a stylesheet from code.
  4. XSLT: Advanced Techniques — The identity transform, modes, parameters, keys and grouping, named templates, and what XSLT 2.0 and 3.0 add.
  5. XQuery — Querying XML like a database with XQuery FLWOR expressions, constructing results, and XQuery 3.1 maps and JSON.

XML in Code

  1. XML in Python — Reading, building and writing XML in Python with the standard library's ElementTree and with lxml, and when to use which.
  2. XML in PHP — SimpleXML for quick reading, DOMDocument and DOMXPath for full control, and XMLWriter and XMLReader for large documents.
  3. XML in Java — Java's built-in XML APIs: DOM, SAX, StAX and the Transformer, plus secure parser settings and JAXB-style data binding.
  4. XML in JavaScript — Parsing and creating XML in the browser with DOMParser, XMLSerializer, document.evaluate (XPath) and XSLTProcessor, and options for Node.js.
  5. DOM vs Streaming Parsers — Why tree parsers run out of memory on large files, and how to process XML as a stream with iterparse, XMLReader and StAX.
  6. XML Security: XXE and Entity Attacks — XML external entity (XXE) attacks, billion-laughs entity expansion, SSRF through DTDs, and safe parser settings in Python, PHP, Java and .NET.

XML in the Real World

  1. SOAP and WSDL — How SOAP web services exchange XML envelopes, what a WSDL describes, how to read responses and faults, and how SOAP compares with REST.
  2. RSS, Atom and Sitemaps — The XML formats behind web feeds and search-engine sitemaps: reading RSS 2.0 and Atom, and generating a sitemap.xml.
  3. SVG and Office Documents — Two everyday XML formats you may not think of as XML: SVG graphics and Office Open XML files (.docx, .xlsx), and how to generate and read them.
  4. XML Configuration Files — Reading and editing XML configuration found in real projects: Maven pom.xml, Android manifests, .NET project files and more.
  5. XML vs JSON vs YAML — How XML, JSON and YAML compare, how to convert between XML and JSON without losing information, and how to choose a format.
  6. XML Next Steps — Where to go after this tutorial: practice ideas, the XML in Production course, interview questions, and official references.

Was this page helpful?