Open In App

Which tag is used to find the version of XML and syntax ?

Last Updated : 07 Dec, 2021
Like Article

Extensible Markup Language (XML) is a markup language, defining a ruleset for encoding documents in both formats that is human-readable and machine-readable. The design goals of XML focus on simplicity, generality, and usability across the Internet. XML is designed to be self-descriptive along with storing and transporting the data. It is a textual data format with strong support via Unicode for different human languages. Although the design of XML focuses on documents, the language is widely used for the representation of arbitrary data structures such as those used in web services. In this article, we will learn about the tags used to find the version of XML and its syntaxes. We will use DOM to find a version of XML.

DOM (Document Object Model) represents an entire HTML or XML document, serves as the root of the document tree. It has a number of attributes like xmlVersion, encoding, etc.

xmlVersion: An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the “XML” feature, the value is “1.0”.



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


  • This line represents the XML Prolog or XML declaration.
  • It is an optional line i.e, it can be either used or not in an XML document. However, it should be the very first line if used.
  • The version=”1.0″ is the version of the XML currently used. There are various versions of XML available.
  • The encoding= ”UTF-8″ specifies the character encoding used while writing an XML document, for example, êèé is for French and so on. Its default value is “UTF-8”.
  • This declaration is case-sensitive. For example “xml” should be in lower case.

Example 1: This example describes the XML version.


$doc = new DOMDocument;
$doc->loadXML('<?xml version="1.0" encoding="ISO-8859-1"?><from>John</from>');
$version = $doc->xmlVersion; // 1.0
$encoding = $doc->encoding; // ISO-8859-1
echo "Version is:", $version;
echo "\r\n";
echo "encoding is:", $encoding;


Version is:1.0
encoding is:ISO-8859-1

Example 2: This example describes the self-defined tags like the “To” tag and “from” tag.


<?xml version="1.0" encoding="UTF-8"?>
<body>Meeting with Parent</body>
<text>Progress Discussion</text>


Syntax rules for Root Element:

Every XML file should have one or more Root elements to avoid an error. For example below code is wrong because it’s not containing the Root element.


<subject>Regarding assignment submission</subject>
<text>All students will have to submit assignment by tomorrow.</text>



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads