Introduction to XML

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.

Understanding XML Syntax and Rules

XML is a combination of five basic components,

XML ComponentDetailsBasic StructureRules & Tips
ElementConsists 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.
AttributeAttributes 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 ContentThe data enclosed between the opening and closing tags of an element.<name>John</name>Special character entities like &lt; represent reserved characters within text content.
Root ElementThe outermost element in an XML document, containing all the other elements.<root> <!-- other XML elements go here --> </root>
CommentsEnclosed in , Comments contain information for humans and are ignored by XML parsers.<!-- This is a comment -->

Special Rules:

  • Characters like <, >, &, must be replaced with entities (&lt;, &gt;, &amp;) to avoid parsing errors.
  • Empty elements can be represented as self-closing tags (e.g., <empty />).