News & UpdatesProgrammingWeb programming Store My Projects

XML Tutorial – 02 – Syntax Rules I

To make an XML document create an empty text file and give it a .xml file extension. The first line in the document must be the XML declaration. This line defines the XML version and the character encoding used in the document.

<?xml version="1.0" encoding="UTF-8"?>

This XML document will describe a book so the first tag is called book. Just as in XHTML the tags are recognized by the angle brackets and all tags must have a closing tag (except for the XML declaration). Unlike HTML, XML tags are not predefined. Any tag names can be used, but they shouldn’t contain spaces or start with numbers or punctuations. Either upper or lower case letters can be used, as long as the opening and closing tags have same casing.

<?xml version="1.0" encoding="UTF-8"?>

This first element is called the root element and each XML document can have only one of them. Inside the root two child elements are included: title and chapter. These are sister elements to each other, because they have the same parent element. All elements can contain both text and child elements.

<?xml version="1.0" encoding="UTF-8"?>
  <title>Learning XML</title>
  <chapter>What is XML</chapter>