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

07 Dec, 2021
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,
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, êèé 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.
PHP
<?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-1echo "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
<?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.
XML
<to>Students</to><from>Teacher</from><subject>Regarding assignment submission</subject><text>All students will have to submit assignment by tomorrow.</text>
xml
Reference:
https://www.geeksforgeeks.org/xml-basics/
https://www.geeksforgeeks.org/xml-syntax/?ref=lbp
https://www.geeksforgeeks.org/how-to-parse-and-process-html-xml-using-php/
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
HTML and XML
PHP-XML
Picked
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
REST API (Introduction)
Design a web page using HTML and CSS
Angular File Upload
Form validation using jQuery
How to auto-resize an image to fit a div container using CSS?
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Convert a string to an integer in JavaScript
How to calculate the number of days between two dates in javascript?