Introduction to XML
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
| HTML | XML | |
|---|---|---|
| Purpose | display a page | describe and carry data |
| Tags | predefined (<p>, <h1>) | you invent them (<book>, <price>) |
| Errors | browsers guess and carry on | a mistake makes the whole document invalid |
Where XML is used
| Where | Examples |
|---|---|
| Office files | .xlsx, .docx and .pptx are zipped folders of XML |
| Configuration | pom.xml, .NET config files |
| Web feeds | RSS and Atom |
| Graphics | SVG images are XML |
| Data exchange | banking, 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.