XML
XML
Introduction
XML (Extensible Markup Language) is a markup language designed to store and transport
data in a format that is both human-readable and machine-readable. Developed by the
World Wide Web Consortium (W3C), XML is widely used in web technologies, data
exchange, and configuration files. Unlike HTML, which focuses on the presentation of data,
XML emphasizes the structure and storage of data.
Features of XML
1. Simplicity: XML uses plain text, making it easy to read and write.
2. Platform Independence: XML is hardware and software-independent, allowing
seamless data exchange across systems.
3. Self-descriptive Tags: Tags in XML describe the data they contain, making the
structure self-explanatory.
4. Extensibility: XML allows users to define their custom tags to suit specific needs.
5. Data Validation: XML can validate data using Document Type Definition (DTD) or
XML Schema.
6. Hierarchical Structure: XML data is organized hierarchically, which is ideal for
representing complex relationships.
7. Unicode Support: XML supports Unicode, enabling the representation of data in
various languages.
1. Names can contain letters, numbers, underscores (_), hyphens (-), and periods (.).
2. Names must start with a letter or an underscore; they cannot start with a number or
punctuation character.
3. Names cannot contain spaces.
4. XML names are case-sensitive.
5. Reserved words like "xml" (in any case combination) cannot be used as element
names.
Uses of XML
1. Data Storage and Transport: XML is commonly used to store and exchange data
between systems.
2. Web Services: Used in SOAP and REST APIs for data communication.
3. Configuration Files: XML is used to define settings in applications, such as
.config files.
4. Document Representation: Formats like DOCX and ODT are based on XML.
5. Database Interactions: XML is used to represent data in databases and query
results.
6. RSS Feeds: For syndicating website content.
1. Prolog: Contains the XML declaration and optional processing instructions. Example:
<?xml version="1.0" encoding="UTF-8"?>
2. Elements: The core building blocks, represented by start and end tags. Example:
<name>Disha</name>
3. Attributes: Provide additional information about elements. Example: <student
id="123">Disha</student>
4. Text: The data within the elements. Example: Disha in <name>Disha</name>.
5. Comments: Provide explanatory notes. Example: <!-- This is a comment
-->
6. CDATA Sections: Used for text that should not be parsed by the XML parser.
Example: <![CDATA[<html>Text</html>]]>
Self-descriptiv No Yes
e
XML Parser
An XML Parser is a tool that reads XML documents and provides access to their structure
and data.
DTD is used to define the structure, elements, and attributes of an XML document. It
ensures that the XML document adheres to a specific format.
Example of DTD:
● Styling XML with CSS: XML documents can be styled using CSS by associating an
external stylesheet.