Welcome to the exciting world of XML! In this lesson, we'll dive into the essential XML Declaration that sets the stage for your XML documents.
XML Declaration, also known as the XML prolog, is a line of code that specifies the version of XML and the character encoding used in the document. It's like a blueprint for your XML file, providing essential information for parsing and understanding the document.
<?xml version="1.0" encoding="UTF-8"?>š Note: Always ensure the XML Declaration is the very first line in your XML document.
The version number in the XML Declaration tells the parser which version of XML the document follows. Currently, the most common version is 1.0.
<?xml version="1.0" encoding="UTF-8"?>The encoding specifies the character encoding used in the document. The most common encoding is UTF-8, which supports a wide range of languages and characters.
<?xml version="1.0" encoding="UTF-8"?>The XML Declaration helps in the following ways:
Let's create a simple XML document with an XML Declaration. We'll create an XML file for a book library.
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book id="001">
<title>The Catcher in the Rye</title>
<author>J.D. Salinger</author>
<year>1951</year>
</book>
<!-- More books can be added here... -->
</library>Stay tuned for our next lesson on XML Elements and Attributes! š