Sobes.tech
Intern
198

What is XML?

Answer from AI

sobes.tech AI

XML (eXtensible Markup Language) is an extensible markup language designed for storing, describing, and transmitting data. It is not a programming language.

Main features:

  • Structured: Data is organized in a tree of elements using opening and closing tags.
  • Readable: XML documents are easy to read by both humans and machines.
  • Extensible: Users can create their own tags to describe data.
  • Platform-independent: XML is not tied to any specific platform or programming language.

Applications:

  • Configuration files
  • Data exchange between different systems
  • Document formats (e.g., DocBook, XHTML)

Example of a simple XML document:

<?xml version="1.0" encoding="UTF-8"?>
<person>
    <name>Ivan</name>
    <age>30</age>
    <city>Moscow</city>
</person>

Standard libraries such as xml.etree.ElementTree or the third-party lxml (more powerful and efficient) are used in Python for processing XML.

import xml.etree.ElementTree as ET

xml_string = """
<person>
    <name>Ivan</name>
    <age>30</age>
    <city>Moscow</city>
</person>
"""

root = ET.fromstring(xml_string)

name = root.find('name').text
age = root.find('age').text

print(f"Name: {name}, Age: {age}")