XML is a markup language designed with a focus on storing and transporting data. It contains a set of rules and syntax to encode documents in a format that is both human-readable and machine-readable. XML is often used for configuration files, data exchange between systems, and representing structured data.
XML is a combination of five basic components,
XML Component | Details | Basic Structure | Rules & Tips |
---|---|---|---|
Element | Consists of an opening tag, content, and a closing tag. | <person> <name>John</name> <age>25</age> </person> | Higly case sensitive. For example, <age> and <Age> are treated as different elements. |
Attribute | Attributes includes extra details about an element. It appears within the opening tag. | <person gender="male">John</person> | Attributes should be in the openning tag. |
Text Content | The data enclosed between the opening and closing tags of an element. | <name>John</name> | Special character entities like < ; represent reserved characters within text content. |
Root Element | The outermost element in an XML document, containing all the other elements. | <root> <!-- other XML elements go here --> </root> | |
Comments | Enclosed in , Comments contain information for humans and are ignored by XML parsers. | <!-- This is a comment --> |
Special Rules:
<
, >
, &
, must be replaced with entities (<
;, >
;, &
;) to avoid parsing errors.<empty />
).