/    /  XML – Validation

XML – Validation

XML validation involves in to determine if the XML document is valid and well-formed. Here, we need understand that even a word document may contain errors while typing the information. Validating a word document involves in ensuring that the information entered in the document is grammatically correct with right alignment of paragraphs. In XML document, we need to validate if it well-formed and valid.

How can we define a Well-formed XML document and Valid XML document ?

Every design language will have their own set of rules. In the same way, even XML have its own syntactical rules to become a well-formed XML document.

Rules to become a Well-Formed XML Document:

♦ XML Documents should have one root element.

♦ XML elements should have starting and ending tags properly nested.

♦ XML attribute values should be in quotes.

♦ XML tags are case sensitive.

Example:

This is not well formed.Find the observations below:

<?xml version="1.0" encoding="UTF-8"?> 
<customer_list> 
	<customer> 
		<name> Sanjay</name> 
		<location> Mumbai</ablocation> 
	</customer> 
	<customer> 
		<name> Micheal</name> 
		<location> Washington</Location> 
	</customer> 
</customer_list> 

Observations:

1. First location end tag contains ab
2. Second location end tag contains L (capital Letter)

Example:

This is well-formed

<?xml version="1.0" encoding="UTF-8"?> 
<customer_list> 
	<customer> 
		<name> Sanjay</name> 
		<location> Mumbai</location> 
	</customer> 
	<customer> 
		<name> Micheal</name> 
		<location> Washington</location> 
	</customer> 
</customer_list> 

Now, a VALID XML document is not same as well-formed document. But all valid XML documents are well-formed documents. In order to be a valid XMl document it needs to follow the rules of Document Type Definitions(DTD).DTD needs to be referenced in XML document as we read in our previous document.