XML looks a lot like HTML, but it follows a few simple rules that keep everything neat and tidy. These rules make sure that the information stays readable and portable.
Like HTML often does, XML starts with a short line that tells the program what version of XML is being used:
<?xml version="1.0" encoding="UTF-8"?>
Since XML is not made to display information, there are no "head" or "body" sections. Instead, the main information is contained in the root element. Everything in the file goes in this root.
<book>
<title>Harry Potter and the Chamber of Secrets</title>
<author>JK Rowling</author>
</book>
Just like HTML, every piece of data in XML is surrounded by two tags. These tags are identical, except that the ending tag has a slash to close that tag. Tags can also apply attributes to the data, giving it more context:
<book genre="fiction">
<title>Harry Potter and the Chamber of Secrets</title>
</book>
In this case, the book tag is given an attribute of fiction.
Some key rules for well-formed XML include:
If an XML file follows the rules above, it is well-formed. Sometimes, it may need to follow additional rules, called a schema. XML files that follow the schema are considered valid.
Sources: W3Schools MDN TutorialsPoint