eXtensible Markup Language: Machine and Human Readable Data Storage
XML stands for eXtensible Markup Language:
Here's how a basic XML document looks:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
You can see that both HTML and XML look similar, and for good reason:
However, they have some key differences:
This line is called the XML prolog:
<?xml version="1.0" encoding="UTF-8"?>
The XML prolog is optional. If it exists, it must come first in the document. You can specify general document values, like version and encoding, within the prolog.
XML documents must contain one root element that is the parent of all other elements. In this example, <note>
is the root element:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
In HTML, some elements might work well, even with a missing closing tag. In XML, it is illegal to omit the closing tag. All elements must have a closing tag.
<!-- The </testing> tag is missing, so this would fail -->
<?xml version="1.0" encoding="UTF-8"?>
<note>
<testing>What is going on?
</note>
<!-- This is proper syntax -->
<?xml version="1.0" encoding="UTF-8"?>
<note>
<testing>What is going on?</testing>
</note>
Note: The XML prolog does not have a closing tag. This is not an error. The prolog is not a part of the XML document.
XML tags are case sensitive. The tag <Letter>
is different from the tag <letter>
. Opening and closing tags must be written with the same case:
<!-- This is incorrect -->
<Message>This is incorrect</message>
<!-- This is correct -->
<message>This is correct</message>