XML | Syntax Last Updated : 22 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Prerequisite: XML | Basics In this article, we are going to discuss XML syntax rule which is used while writing an XML document or an XML application. It is a very simple and straight forward to learn and code. Below is a complete XML document to discuss each component in detail. XML <?xml version="1.0" encoding="UTF-8"?> <message> <to>Students</to> <from>Teacher</from> <subject>Regarding assignment submission</subject> <text>All students will have to submit assignment by tomorrow.</text> </message> Syntax rules for XML declaration or XML Prolog: XML <?xml version="1.0" encoding="UTF-8"?> Below is the explanation of each point. This line is called XML Prolog or XML declaration.This line is optional 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". For more about character encoding click here.This declaration is case sensitive for example "xml" should be in lower case in . Syntax rules for Root Element: Every XML files should have one or more Root elements to avoid error. For example below code is wrong because it's not containing 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> In the first example the Root element is <message> and all the remaining elements <to>, <from> etc is the child element and reside within the root element.It is case sensitive.The XML element should have a closing element for example <text category = "message">Hi</text> is correct but <text category = "message">Hi is not correct because it does not contain the closing element and it will throw an error and vice-versa.The elements in XML should be nested properly otherwise it will throw an error. For example <to><from>Geeks</from></to> is nested correctly but <to><from>Geeks</to></from> is wrong because if <from> is opened inside the <to> element then this should also end inside of the </to> element.It is also case sensitive i.e, the starting and closing element should be in the same case. For example <to>....</to> is correct but <to>.....</To> is not correct and it will throw an error.The XML attribute is having two part one is Name and other is its value. It resides inside of the opening of an XML element. For example: <text category = "message">All students will have to submit the assignment by tomorrow.</text> Here category is the attribute name and message is its value and the attribute value should either be in a single quotation or in double quotation otherwise it will throw an error. The Attribute Name is written without any quotation.The XML attribute is also case sensitive.An XML element can have multiple attributes but can not have the same attribute names in the same element. For example: <text category ="message" purpose = "greet">GeeksforGeeks</text> Above attributes is correct because of having multiple attributes with the different attribute name. <text category ="message" category = "greet">GeeksforGeeks</text> Above attribute is wrong because of having the same attribute name in a single element. XML Comments: Correct syntax for writing XML comments are: <!– It is comment section –>Incorrect comments: <!– It is comment — section –> i.e. Two dashes in between the comment is not allowed. Comment More infoAdvertise with us Next Article XML | Syntax K Kanchan_Ray Follow Improve Article Tags : Software Engineering HTML and XML Similar Reads XML | Tags XML tags are the important features of XML document. It is similar to HTML but XML is more flexible then HTML. It allows to create new tags (user defined tags). The first element of XML document is called root element. The simple XML document contain opening tag and closing tag. The XML tags are cas 2 min read XML | Elements The XML elements are the basic building block of the XML document. It is used as a container to store text elements, attributes, media objects etc. Every XML documents contain at least one element whose scopes are delimited by start and end tags or in case of empty elements it is delimited by an emp 2 min read XML Tutorial XML, or Extensible Markup Language, is a way to structure and organize information in a text format that is easy for computers to read. It uses tags, similar to those in HTML, to define different types of data inside a document. XML allows data to be stored and shared in a consistent and structured 4 min read XML | Basics Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The design goals of XML focus on simplicity, generality, and usability across the Internet. It is a textual data format with strong s 3 min read HTML vs XML HTML (Hyper Text Markup Language) is used to create web pages and web applications. It is a markup language. By HTML we can create our static page. It is used for displaying the data not to transport the data. HTML is a combination of Hypertext and Markup language. Hypertext defines the link between 3 min read Like