


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















What is XML?
XML stands for eXtensible Markup Language XML is a markup language much like HTML XML was designed to store and transport data XML was designed to be self-descriptive XML is a W3C Recommendation XML stands for E xtensible M arkup L anguage. It is a text-based markup language derived from Standard Generalized Markup Language (SGML). XML tags identify the data and are used to store and organize the data, rather than specifying how to display it like HTML tags, which are used to display the data. XML is not going to replace HTML in the near future, but it introduces new possibilities by adopting many successful features of HTML. There are three important characteristics of XML that make it useful in a variety of systems and solutions −
XML is extensible − XML allows you to create your own self- descriptive tags, or language, that suits your application. XML carries the data, does not present it − XML allows you to store the data irrespective of how it will be presented. XML is a public standard − XML was developed by an organization called the World Wide Web Consortium (W3C) and is available as an open standard.
XML Usage
A short list of XML usage says it all − XML can work behind the scene to simplify the creation of HTML documents for large web sites. XML can be used to exchange the information between organizations and systems. XML can be used for offloading and reloading of databases. XML can be used to store and arrange the data, which can customize your data handling needs. XML can easily be merged with style sheets to create almost any desired output. Virtually, any type of data can be expressed as an XML document.
Is XML a Programming Language?
A programming language consists of grammar rules and its own vocabulary which is used to create computer programs. These programs instruct the computer to perform specific tasks. XML does not qualify to be a programming language as it does not perform any computation or algorithms. It is usually stored in a simple text file and is processed by special software that is capable of interpreting XML.
The XML above is quite self-descriptive:
It has sender information. It has receiver information It has a heading It has a message body.
But still, the XML above does not DO anything. XML is just information wrapped in tags.
The Difference Between XML and HTML
XML and HTML were designed with different goals:
XML was designed to carry data - with focus on what data is
HTML was designed to display data - with focus on how data looks XML tags are not predefined like HTML tags are
XML Does Not Use Predefined Tags
,
, , etc.XML Separates Data from Presentation
XML does not carry any information about how to be displayed.
The same XML data can be used in many different presentation scenarios.
Because of this, with XML, there is a full separation between data and presentation.
XML is Often a Complement to HTML
In many HTML applications, XML is used to store or transport data, while HTML is used to format and display the same data.
XML Separates Data from HTML
When displaying data in HTML, you should not have to edit the HTML file when the data changes.
With XML, the data can be stored in separate XML files.
With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page.
The following diagram depicts the syntax rules to write different types of markup and text in an XML document.
Let us see each component of the above diagram in detail.
XML Declaration
The XML document can optionally have an XML declaration. It is written as follows −
Where version is the XML version and encoding specifies the character encoding used in the document.
An XML file is structured by several XML-elements, also called XML-nodes or XML-tags. The names of XML-elements are enclosed in triangular brackets < > as shown below −
Syntax Rules for Tags and Elements
Element Syntax − Each XML-element needs to be closed either with start or with end elements as shown below −
....
or in simple-cases, just this way −
Nesting of Elements − An XML-element can contain multiple XML-elements as its children, but the children
elements must not overlap. i.e., an end tag of an element must have the same name as that of the most recent unmatched start tag. The Following example shows incorrect nested tags −
TutorialsPoint
The Following example shows correct nested tags −
TutorialsPoint
Root Element − An XML document can have only one root element. For example, following is not a correct XML
An attribute specifies a single property for the element, using a name/value pair. An XML-element can have one or more attributes. For example −
Tutorialspoint!
Here href is the attribute name and http://www.tutorialspoint.com/ is attribute value.
Syntax Rules for XML Attributes
Attribute names in XML (unlike HTML) are case sensitive. That is, HREF and href are considered two different XML attributes. Same attribute cannot have two values in a syntax. The following example shows incorrect syntax because the attribute b is specified twice
....
Attribute names are defined without quotation marks, whereas attribute values must always appear in quotation marks. Following example demonstrates incorrect xml syntax
....
In the above syntax, the attribute value is not defined in quotation marks.
XML References
References usually allow you to add or include additional text or markup in an XML document. References always begin with the symbol "&" which is a reserved character and end with the symbol ";". XML has two types of references − Entity References − An entity reference contains a name between the start and the end delimiters. For example & where amp is name. The name refers to a predefined string of text and/or markup.
representing molecular structure or a mathematical equation.
XML Document Example
A simple document is shown in the following example −
Tanmay Patil TutorialsPoint (011) 123-4567
Document Prolog comes at the top of the document, before the root element. This section contains − XML declaration Document type declaration
You can learn more about XML declaration in this chapter − XML Declaration
Document Elements are the building blocks of XML. These divide the document into a hierarchy of sections, each serving a specific purpose. You can separate a document into multiple sections so that they can be rendered differently, or used by a search engine. The elements can be containers, with a combination of text and other elements. XML declaration contains details that prepare an XML processor to parse the XML document. It is optional, but when used, it must appear in the first line of the XML document.
Syntax
Following syntax shows XML declaration −
xml version = "version_number" encoding = "encoding_declaration"
information from an external source, such as external document type definition (DTD), for its content. The default value is set to no. Setting it to yes tells the processor there are no external declarations required for parsing the document.
Rules
An XML declaration should abide with the following rules − If the XML declaration is present in the XML, it must be placed as the first line in the XML document. If the XML declaration is included, it must contain version number attribute. The Parameter names and values are case-sensitive. The names are always in lower case.
The order of placing the parameters is important. The correct order is: version, encoding and standalone. Either single or double quotes may be used. The XML declaration has no closing tag i.e. ****
XML Declaration Examples
Following are few examples of XML declarations − XML declaration with no parameters −
XML declaration with version definition −
XML declaration with all parameters defined −
XML declaration with all parameters defined in single quotes −