CodeMIRAI
0 XP

Introduction to XML

2 min read 2 runnable examples Quiz included

XML (eXtensible Markup Language) is a format for storing and exchanging structured data. It looks like HTML, but instead of predefined tags, you invent tags that describe your data.

XML
<?xml version="1.0" encoding="UTF-8"?>
<book>
  <title>Learning Python</title>
  <author>Mark Lutz</author>
  <year>2013</year>
  <price currency="USD">44.99</price>
</book>

Press Run: CodeMIRAI checks the document with a real XML parser and shows its structure.

XML vs HTML

HTMLXML
Purposedisplay a pagedescribe and carry data
Tagspredefined (<p>, <h1>)you invent them (<book>, <price>)
Errorsbrowsers guess and carry ona mistake makes the whole document invalid

Where XML is used

WhereExamples
Office files .xlsx, .docx and .pptx are zipped folders of XML
Configuration Android layouts, Maven's pom.xml, .NET config files
Web feedsRSS and Atom
GraphicsSVG images are XML
Data exchangebanking, healthcare and government systems (SOAP web services)

A document with repeating data

XML
<?xml version="1.0" encoding="UTF-8"?>
<library>
  <book id="1">
    <title>Clean Code</title>
    <author>Robert C. Martin</author>
  </book>
  <book id="2">
    <title>The Pragmatic Programmer</title>
    <author>Andrew Hunt</author>
  </book>
</library>

Each <book> has the same structure, which makes the data easy for programs to read.

Finished this lesson?Mark it complete to earn +20 XP and move your progress on.