Open In App

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

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”.

 



Syntax:

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

Where,

Example 1: This example describes the XML version.




<?php
$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;
?>

Output:

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"?>
<note>
<to>Students</to>
<from>Teacher</from>
<heading>Reminder</heading>
<body>Meeting with Parent</body>
<text>Progress Discussion</text>
</note>

Output:

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.




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

xml

Reference:


Article Tags :