XML - XML Validator
What is XML?
XML (eXtensible Markup Language) is a language used to store and transport data. It is readable by both humans and machines.
Example of a simple XML file:
<student>
<name>John</name>
<age>20</age>
<course>Computer Science</course>
</student>
What is an XML Validator?
An XML Validator is a tool or program that checks if your XML file is correct and follows the rules.
There are two types of validation:
1. Well-Formed XML
This means your XML follows basic syntax rules.
✔️ Rules for well-formed XML:
-
Must have one root element
-
All tags must be properly opened and closed
-
Tags must be nested correctly
-
Attribute values must be in quotes
Example of not well-formed XML:
<student>
<name>John</name>
<age>20<age> <!-- Closing tag is wrong -->
</student>
A well-formed XML can still be invalid if it doesn’t follow a defined structure (like a grammar).
2. Valid XML
This means your XML is well-formed AND follows the structure rules defined in:
-
DTD (Document Type Definition)
-
XSD (XML Schema Definition)
These define:
-
What tags are allowed
-
The order of tags
-
What data types the values should have (for example: age must be a number)
DTD (Document Type Definition)
Defines the structure of your XML using a simpler syntax.