XML (Extensible Markup Language) is a text-based markup language used to store, organize, and exchange structured data.
Unlike HTML, which mainly describes how webpage content is presented, XML focuses on describing the meaning and structure of information through custom tags.
XML is commonly used in APIs, configuration files, data feeds, document formats, and system integrations.
XML organizes data using nested elements.
A typical process includes:
XML documents must follow strict syntax rules to be considered well-formed.
An XML document might look like this:
<product>
<name>Wireless Mouse</name>
<price currency="USD">29.99</price>
<available>true</available>
</product>
In this example:
product is the root element.name, price, and available are child elements.currency is an attribute associated with the price element.XML and JSON are both used to exchange structured information.
JSON is often more compact for modern web APIs, while XML remains common in enterprise systems, document formats, and older integrations.
XML and HTML both use tags, but they serve different purposes.
XML allows developers to create custom tags, while HTML uses a predefined set of elements.
Applications should use secure parser configurations when processing untrusted XML.
Web scraping applications may encounter XML in sitemaps, RSS feeds, APIs, and downloadable data files.
A scraper can parse XML to extract URLs, product information, publication dates, or other structured values.
Because XML already provides a defined hierarchy, extracting information is often simpler than processing unstructured webpage text.
The following Python example parses an XML document:
import xml.etree.ElementTree as ET
xml_data = """
<product>
<name>Wireless Mouse</name>
<price>29.99</price>
</product>
"""
root = ET.fromstring(xml_data)
name = root.find("name").text
price = root.find("price").text
print(name, price)
Output:
Wireless Mouse 29.99
The parser identifies the XML elements and retrieves their values for further processing.
XML is a markup language designed for storing and exchanging structured, hierarchical data.
It remains important for APIs, enterprise integrations, configuration files, and web data feeds. Although JSON is often more compact for modern applications, XML provides strong structure, extensibility, and validation capabilities.