XML - Extensible Markup Language
Learn to structure data with XML and its associated technologies
🎯 What is XML?
XML (eXtensible Markup Language) is a markup language designed to store and transport data in a structured way that is readable by both humans and machines.
Self-descriptive
Tag names describe the content
Independent
Doesn't depend on any platform or programming language
Extensible
You can create your own tags according to your needs
W3C Standard
Maintained by the World Wide Web Consortium
📝 Basic Syntax of XML
<?xml version="1.0" encoding="UTF-8"?>
<biblioteca>
<libro id="001">
<titulo>El Quijote</titulo>
<autor>Miguel de Cervantes</autor>
<anio>1605</anio>
<genero>Novela</genero>
</libro>
<libro id="002">
<titulo>Cien años de soledad</titulo>
<autor>Gabriel García Márquez</autor>
<anio>1967</anio>
<genero>Realismo mágico</genero>
</libro>
</biblioteca>
Key Elements:
- Declaration XML: First line with version and encoding
- Root element: A single element that contains everything (
<biblioteca>) - Tags: Must always be closed (
<titulo>...</titulo>) - Attributes: Additional information in elements (
id="001") - Nesting: Elements inside other elements
📜 Essential Rules of XML
XML Declaration
Every XML document must start with a declaration specifying the version and encoding.
<?xml version="1.0" encoding="UTF-8"?>
Root Element Single
There can only be one root element containing all the other elements.
Tags Closed
All tags must be closed, either with a closing tag or as self-contained tags.
<nombre>valor</nombre>
Case Sensitive
XML distinguishes between uppercase and lowercase in tag names.
Attributes in Quotes
Attribute values must always be enclosed in single or double quotes.
id="123"
Nesting Correct
Elements must be nested correctly without overlapping.
🔧 Technologies Associated with XML
DTD - Document Type Definition
Schema that defines the structure of a document XML.
<!ELEMENT biblioteca (libro+)>
<!ELEMENT libro (titulo, autor, anio, genero)>
<!ATTLIST libro id CDATA #REQUIRED>
<!ELEMENT titulo (#PCDATA)>
XSD - XML Schema Definition
A more powerful and expressive schema than DTD, also in XML.
<xs:element name="libro">
<xs:complexType>
<xs:sequence>
<xs:element name="titulo" type="xs:string"/>
<xs:element name="autor" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer"/>
</xs:complexType>
</xs:element>
XPath - XML Path Language
Language to navigate and select nodes in XML.
/biblioteca/libro[titulo='El Quijote']
//autor[contains(text(), 'Cervantes')]
/biblioteca/libro[@id='001']/titulo
XSLT - XML Transformations
Language to transform XML documents into other formats (HTML, XML, text).
<xsl:template match="/">
<html>
<xsl:for-each select="biblioteca/libro">
<div class="libro">
<h2><xsl:value-of select="titulo"/></h2>
</div>
</xsl:for-each>
</html>
</xsl:template>
XQuery - XML Query Language
Language to query XML (similar to SQL for databases).
for $libro in /biblioteca/libro
where $libro/anio > 1900
return $libro/titulo
🎮 Interactive Examples
Select an example to see it in action and learn by practicing:
✍️ XML Interactive Editor
Write your own XML here and validate it in real time:
Write your XML:
Result:
XML Write "Validate"
🏢 Common Use Cases
Web Services
SOAP and RESTful APIs frequently use XML to exchange data
Settings
Configuration files in applications and frameworks
Storage
XML Native databases and data persistence
Documentation
Formats like DocBook for technical documentation