The Wayback Machine - https://web.archive.org/web/20241121011038/https://www.geeksforgeeks.org/how-to-define-structure-of-xml-document/
Open In App

How to define structure of XML document ?

Last Updated : 09 Mar, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

An XML (EXtensible Markup Language) Document contains declarations, elements, text, and attributes. It is made up of entities (storing units) and It tells us the structure of the data it refers to. It is used to provide a standard format of data transmission. As it helps in message delivery, it is not always stored physically, i.e. in a disk but generated dynamically but its structure always remains the same.

XML Standard structure and its rules:

Rule 1: Its standard format consists of an XML prolog which contains both XML Declaration and XML DTD (Document Type Definition) and the body. If the XML prolog is present, it should always be the beginning of the document. The XML Version, by default, is 1.0, and including only this forms the shortest XML Declaration. UTF-8 is the default character encoding and is one of seven character-encoding schemes. If it is not present, it can result in some encoding errors.

Syntax of XML Declaration:

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

Syntax of DTD:

<!DOCTYPE root-element [<!element-declarations>]>

Example:

XML




<!DOCTYPE website [
  <!ELEMENT website (name,company,phone)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT company (#PCDATA)>
  <!ELEMENT phone (#PCDATA)>
]>
  
<website>
  <name>GeeksforGeeks</name>
  <company>GeeksforGeeks</company>
  <phone>011-24567981</phone>
</website>


Rule 2: XML Documents must have a root element (the supreme parent element) and its child elements (sub-elements). To have a better view of the hierarchy of the data elements, XML follows the XML tree structure which comprises of one single root (parent) and multiple leaves (children).

Source Code of the above diagram:

XML




<?xml version="1.0" encoding="UTF-8"?>
<website>
    <company category="geeksforgeeks">
        <title>Machine learning</title>
        <author>aarti majumdar</author>
        <year>2022</year>
    </company>
    <company category="geeksforgeeks">
        <title>Web Development</title>
        <author>aarti majumdar</author>
        <year>2022</year>
    </company>
    <company category="geeksforgeekse">
        <title>XML</title>
        <author>aarti majumdar</author>
        <year>2022</year>
    </company>
</website>


Rule 3: All XML Elements are required to have Closing and opening Tags(similar to HTML).

XML




<message>Welcome to GeeksforGeeks</message>


Rule 4: The opening and closing tags are case-sensitive. For Example, <Message> is different from <message> from above example.

Rule 5: Values of XML attributes are required to have quotations:

XML




<website category="open source">
    <company>geeksforgeeks</company>
</website>


Rule 6: White-Spaces are retained and maintained in XML.

XML




<message>welcome     to            geeksforgeeks</message>


Rule 7: Comments can be defined in XML enclosed between <!– and –> tags.

XML




<!-- XML Comments are defined like this -->


Rule 8: XML elements must be nested properly.

XML




<message>
    <company>GeeksforGeeks</company>
</message>




Similar Reads

How to check the structure of an XML Document ?
Introduction : XML document is a well-organized collection of components and associated markup. An XML document can hold a wide range of information. For instance, a database having numbers or a mathematical equation etc. Example: A simple document can be created as - <?xml version = "1.0"?> <Student-info> <name>Tanya Bajaj</na
3 min read
Difference Between text/xml and application/xml for Webservice Response
application/xmlThis is the recommended media type for XML data according to the IETF specifications [RFC 7303]. It signifies that the XML content might not be human-readable and could potentially contain processing instructions or other non-human-consumable elements. Syntax:Content-Type: application/xmlThis example demonstrates a web service respon
2 min read
Creating and Sending an XML Document in JQuery
Creating and sending XML documents with jQuery is a common task in web development, particularly for API or web service interactions that require XML format. This article explores different strategies to efficiently construct, modify, and dispatch XML documents using jQuery. Table of Content Using jQuery's .ajax() Method with an XML StringBuilding
4 min read
How to define a title for a document using HTML5 ?
In this article, we will define a title for the document by using the <title> tag. This tag in HTML is used to define the title of the HTML document. It sets the title in the browser toolbar. It provides the title for the web page when it is added to favorites. It displays the title for the page in search engine results. Syntax: <title>
1 min read
How to define style information of a document using HTML5 ?
In this Article, we define style information for a document by using the <style> element in the document. It is used to change our text, viewed on the page. This change includes changing font-size, font-family, font-color, etc. Not only the texts but you can also change the style of a body or part of a page. Now let us look into various attri
1 min read
How to define header for a document or section using HTML ?
The <header> tag in HTML is used to define the header for a document or a section. It contains information related to the title and heading of the related content. The <header> element is intended to usually contain the section’s heading (an h1-h6 element or an <hgroup> element), but this is not required. The <header> elemen
2 min read
How to define information about the document using HTML ?
The <head> tag in HTML is used to define the head portion of the document which contains metadata related to the document. This tag can contain other head elements such as <title>, <meta>, <link>, <style>, <link> etc. The <head> element was mandatory In HTML 4.01, but it can be omitted in the current HTML 5
1 min read
How to define the root of an HTML document ?
The <html> tag in HTML is used to define the root of HTML and XHTML documents. The <html> tag tells the browser that it is an HTML document. It is the second outer container for everything that appears in an HTML document followed by the <!DOCTYPE> tag. The <html> tag requires a starting and end tag. Syntax: <html> HTM
1 min read
How to define metadata about an HTML document in HTML5 ?
The metadata means the information about data. The <meta> tag in HTML provides information about HTML Document or in simple words, it provides important information about a document. These tags are basically used to add name/value pairs to describe properties of HTML documents, such as expiry date, author name, list of keywords, document auth
1 min read
How to define the document's body in HTML5 ?
The document's body in HTML5 is defined by the <body> tag which is placed with in the <html> tags and just after the <head> tag.The body tag can include: headings tags : <h1>, <h2>, <h3> and so on.paragraph tag: <p>line break tag: <br>horizontal rule tag: <hr>image and video tags: <img>
1 min read
How to define a section in a document in HTML5 ?
In this article, we will discuss how to define a section in a document in html5. We can create a section in the document using the Section tag. HTML <section> Tag: Section tags divide content into section and subsection. The section tag is used when there is a requirement for two header, footer, and other sections of the document. Syntax:
1 min read
How to define a text element that inserted into a document in HTML5 ?
In this article, we will learn how to define some text that has been inserted into a document. This can be used to show recent changes in the text content and is mostly used after the text that is to be deleted or is outdated. Approach: We will use the <ins> element to specify text that has been inserted into the document. The browser usually
2 min read
How to define a text that has been deleted from the document in HTML5 ?
In this article, we will learn how to define some text that has been deleted from the document. This can be used to show a recent update in content or remove content that may be incorrect. It is usually followed by text that has been updated or corrected. We will use the <del> element to specify text that has been deleted from the document. T
2 min read
Which tag is used to define the header for HTML document ?
The <header> tag in HTML is used to define the header for a document. It contains information related to the title and heading of the related content. The <header> element is intended to usually contain the section’s heading (an h1-h6 element or an <hgroup> element), but this is not required. The <header> element can also be
2 min read
How to define the relationship between a document and the external resources?
To create the relationship between a document and the external resources by using the <link> Element. This tag is used to define a link between a document and an external resource. The link tag is used to link to external style sheets. This element can appear multiple times but it goes only in the head section. The link element is empty, it c
1 min read
How to fix “No character encoding declared at document level” in HTML Document ?
This article intends to solve the “No character encoding declared at document level” issue in your HTML program. So, before getting to the solution, we need to understand what this issue means. And for that first, we need to know about character encoding in HTML. What is character encoding in HTML? Character encoding is a system used to represent c
5 min read
HTML Course Structure of an HTML Document
HTML(Hypertext Markup Language), structures web pages. Unlike programming languages, it isn't compiled or interpreted. Browsers render HTML directly, displaying content without typical errors. It's a markup language, not a programming one, making execution smooth without encountering compilation or interpretation issues. Table of Content HTML Docum
3 min read
Web technologies | HTML and XML | Question 1
Which of the following is an advantage of putting presentation information in a separate CSS file rather than in HTML itself? (A) The content becomes easy to manage (B) Becomes easy to make site for different devices like mobile by making separate CSS files (C) CSS Files are generally cached and therefore decrease server load and network traffic. (
1 min read
Displaying XML Using CSS
XML stands for Extensible Markup Language. It is a dynamic markup language. It is used to transform data from one form to another form. An XML file can be displayed using two ways. These are as follows :- Cascading Style Sheet Extensible Stylesheet Language Transformation Displaying XML file using CSS : CSS can be used to display the contents of th
4 min read
Displaying XML Using XSLT
XSLT stands for Extensible Stylesheet Language Transformation. XSLT is used to transform XML document from one form to another form. XSLT uses Xpath to perform matching of nodes to perform these transformation . The result of applying XSLT to XML document could be an another XML document, HTML, text or any another document from technology perspecti
3 min read
XML | Syntax
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. C/C++ Code &lt;?xml version=&quot;1.0&quot; encoding=
3 min read
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 case sensitive i.e. <root> and <Root> bot
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 empty tag. Syntax: <element-name attributes> Co
2 min read
XML | Attributes
Prerequisite: XML | BasicsThe XML attribute is a part of an XML element. The addition of attribute in XML element gives more precise properties of the element i.e, it enhances the properties of the XML element.Syntax: <element_name attribute1 attribute2 ... > Contents... </element_name> In the above syntax element_name is the name of an
3 min read
Convert multidimensional array to XML file in PHP
Given a multi-dimensional array and the task is to convert this array into an XML file. To converting the multi-dimensional array into an xml file, create an XML file and use appendChild() and createElement() function to add array element into XML file. Example: First, create a PHP Multidimensional Array for converting that array into the XML file
2 min read
PHP | XMLReader XML() Function
The XMLReader::XML() function is an inbuilt function in PHP which is used to set the data containing the XML to parse. XML() function serves the same purpose as open function but the only difference is former accepts XML as string while later accepts it as a separate .xml file. Syntax: bool XMLReader::XML( string $source, string $encoding, int $opt
2 min read
XML Full Form
XML stands for EXtensible Markup Language XML is s text-based markup language, by XML we can create our own tags which is used as a data indexing in web application. No predefined tags are available in XML. XML is extended from Standard Generalized Markup Language(SGML) The tags which we are created using XML, that are identifying or indexing the d
5 min read
How to parse and process HTML/XML using PHP ?
In this article, we will learn how to process XML using PHP. We have already learnt the basics of XML and their differences with respect to HTML. Different elements of XML can be learnt from XML Elements to understand the working of the following programs. The simplexml_load_string() function is used to parse the given XML and then the XML object c
2 min read
SVG xml:lang Attribute
The xml:lang attribute in SVG is used to indicate the primary language that is used in the contents and attributes containing text content on the website. It is allowed in all XML dialects as it is a universal attribute. All elements use this attribute. Syntax: xml:lang = "language-tag" Attribute Values: The attribute accepts values as mentioned ab
1 min read
Difference Between HTML, XML and DHTML
1. HTML HTML stands for HyperText Markup Language.Used to design the layout of a document and to specify the hyperlinks.Tells the browser how to display text, pictures, and other support media.Support multimedia and new page layout features.Easy to integrate with other programming languages.HTML consists of a series of elements.Provides many tags f
2 min read
Article Tags :
three90RightbarBannerImg