<XML/>
eXtensible Markup Language
Press β or click to begin your journey
<xml>
</xml>
<data>
</data>
<tag>
</tag>
What is Markup?
Adding meaning to text through special annotations
π
Plain Text
Just raw content without any structure or meaning attached
π·οΈ
Markup Language
Text + Tags that describe what the content means or how to display it
π§
Purpose
Makes data readable by both humans AND machines
XML Defined
e X tensible
M arkup
L anguage
Extensible: Create your own custom tags - no predefined vocabulary
Markup: Uses tags to annotate and structure data
Language: A standardized way for systems to communicate
Self-describing: Tags explain what the data means
XML History
1960s
GML (Generalized Markup Language) created at IBM
1986
SGML becomes an ISO standard
1996
XML development begins at W3C
1998
XML 1.0 officially released!
XML Document Structure
Every XML document follows a precise hierarchy
<?xml version="1.0"?>
<root>
XML Declaration
The prolog tells parsers how to read the document
<?xml
version ="1.0"
encoding ="UTF-8"
standalone ="yes"
?>
version
XML version (1.0 or 1.1)
encoding
Character encoding (UTF-8, ISO-8859-1)
standalone
External dependencies (yes/no)
XML Elements
The building blocks of every XML document
<element> Content goes here </element>
π¦
Opening Tag
<element> marks where an element begins
π
Content
Text, child elements, or mixed content
π
Closing Tag
</element> marks where it ends
XML Attributes
Add metadata and properties to your elements
<book
id ="001"
category ="fiction"
lang ="en" >
<title> The Great Story </title>
</book>
β Always quoted
Values must be in single or double quotes
β In opening tag
Attributes only appear in the start tag
β Unique per element
No duplicate attribute names allowed
Nesting & Hierarchy
Elements can contain other elements, creating a tree structure
<library>
<shelf id ="A1" >
<book>
<title> XML Mastery </title>
<author> Jane Doe </author>
</book>
<book>
<title> Data Structures </title>
<author> John Smith </author>
</book>
</shelf>
</library>
Creating XML Documents
Follow these rules for well-formed XML
Must have exactly one root element
All tags must be properly closed
Tags are case-sensitive (<Book> β <book>)
Elements must be properly nested
Attribute values must be quoted
Special characters use entity references
Entity References
How to include special characters in XML
XML vs HTML
Click the cards to flip between the two!
XML
<person>
<name> Alice </name>
<age> 25 </age>
</person>
Data description & transport
HTML
<div>
<h1> Alice </h1>
<p> Age: 25 </p>
</div>
Data display & presentation
Key Differences
XML
β
HTML
Tags
Custom
Predefined
XML
β
HTML
Purpose
Transport
Display
XML
β
HTML
Case
Sensitive
Insensitive
XML
β
HTML
Closing Tags
Required
Optional
XML Validation
Ensuring your XML follows the rules
Well-Formed
β Follows XML syntax rules
β One root element
β Properly nested tags
β Correct attribute format
Valid
β Well-formed AND
β Follows a DTD or Schema
β Correct element order
β Required elements present
DTD - Document Type Definition
A grammar that defines valid XML structure
<!DOCTYPE note [
<!ELEMENT note (to, from, heading, body )>
<!ELEMENT to (#PCDATA )>
<!ELEMENT from (#PCDATA )>
<!ELEMENT heading (#PCDATA )>
<!ELEMENT body (#PCDATA )>
]>
XML Schema (XSD)
A more powerful alternative to DTD
<xs:schema xmlns:xs ="http://www.w3.org/2001/XMLSchema" >
<xs:element name ="book" >
<xs:complexType>
<xs:sequence>
<xs:element name ="title" type ="xs:string" />
<xs:element name ="price" type ="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML Namespaces
Avoiding naming conflicts in complex documents
<root
xmlns:h ="http://www.w3.org/TR/html4/"
xmlns:f ="http://www.furniture.com" >
<h:table>
<h:tr> <h:td> HTML Table </h:td> </h:tr>
</h:table>
<f:table>
<f:name> Coffee Table </f:name>
</f:table>
</root>
XML in the Real World
XML powers many technologies you use daily
π‘ RSS Feeds
π¨ SVG Graphics
π Microsoft Office
π SOAP Web Services
π± Android Layouts
π§ Config Files
π eBooks (EPUB)
πΊοΈ GPS Data (GPX)
πΌ Business Data
π₯ Healthcare (HL7)
XSLT - Transforming XML
Convert XML into HTML, text, or other formats
Input XML
<catalog>
<product>
<name> Widget </name>
<price> 9.99 </price>
</product>
</catalog>
β
Output HTML
<h1> Widget </h1>
<p class ="price" >
$9.99
</p>
XPath - Navigating XML
A query language for selecting XML nodes
/bookstore/book
//book/title
//book[price > 30]
/bookstore/book[1]
Quick Quiz! π―
Which statement about XML is TRUE?
A) XML tags are predefined like HTML
B) XML is case-sensitive
C) XML closing tags are optional
D) XML is used only for web pages
XML Best Practices
Use meaningful element names that describe the data
Keep consistent naming conventions (camelCase or snake_case)
Add comments for complex structures
Use indentation for readability
Validate with DTD or XSD for data integrity
Consider namespaces for large projects
Complete Example
<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns ="http://example.com/bookstore" >
<book id ="bk001" category ="programming" >
<title> Learning XML </title>
<author>
<firstName> Erik </firstName>
<lastName> Ray </lastName>
</author>
<year> 2003 </year>
<price currency ="USD" > 39.95 </price>
<inStock> true </inStock>
</book>
<book id ="bk002" category ="web" >
<title> XML & Web Services </title>
<author>
<firstName> Ethan </firstName>
<lastName> Cerami </lastName>
</author>
<year> 2002 </year>
<price currency ="USD" > 44.95 </price>
<inStock> false </inStock>
</book>
</bookstore>
Why XML Matters
π
Universal
Platform and language independent data exchange
π
Self-Describing
Data carries its own meaning through tags
π§
Extensible
Create custom vocabularies for any domain
β
Validatable
DTD and XSD ensure data integrity
π
Transformable
XSLT converts to any output format
ποΈ
Standard
W3C recommendation since 1998
</>
XML
β
π
π
π‘
Thank You!
Now you understand the power of XML
Structured Data
Custom Tags
Validation
Transformation
Universal Standard