Today we will be learning XML Fundamentals. XML and JSON are different but are used for same thing, that is to store data, structure data. They are called Data Interchange Formats. So let’s have an introduction to XML.
- What is XML?
- XML stands for Extensible Markup Language.
- XML is a markup language like HTML and not a programming language.
- It uses tags, just like HTML.
- XML is not a replacement for HTML.
- XML was created to transport or store data.
- XML is very easy to learn compared to learn any programming language.
- Some XML History
- XML is an application profile of an ISO standard SGML, and most of XML comes from SGML unchanged.
- XML version 1.0 was defined in 1998. It had many minor revisions since then XML 1.0 is the recommended version.
- XML version 1.1 was published in February of 2004, the same day as version 1.0’s third edition. 1.0 is generally suggested over 1.1 unless the project needs specific features of 1.1.
- There have been discussions of an XML 2.0, although no organization has announced plans for work on such a project.
- XML vs. HTML
- There is no comparison between HTML and XML. They are completely different and are used in different situations.
- XML is a Data Interchange Format; it’s a way to structure and store data and also to transport data.
- XML was created to transport and store data and is more behind the scenes.XML has no pre-defined tags.
- HTML is used to display data in a browser and focus on physical presentation. HTML has pre-defined tags.
- Document Structure
- The basic XML file structure is shown below.
- We can define our own “tags” in XML.
- In the XML file structure, the first line is the declaration that contains the document information like version information, character set, etc.
- Declaration must come first in the document.
- Every opening tag should have a closing tag.
- Each XML document has a root element.
- Root element contains the child elements which can in turn have sub-child elements.
- All the sub-child elements in a child element are called the siblings of each other.
- Attributes like gender=”male” can also be given to the tags.
- Use of XML in many different places
- Different computer systems and databases usually have different kinds of formats that are incompatible with each other.
- This is where XML comes in. XML is stored in plain text format and can be read by almost any system.
- XML makes it such that, you can have one system talk to another and share data even though there are completely different platforms.
- It is very extensive and comparable with different kinds of system.
- Today developers are replacing XML with JSON, but this is the one aspect where XML ought to use XML.
- So XML is a software and hardware – independent format for storing data. This is where XML shines.
- Some Advantages of XML
- Simplifies Data Sharing – Can be used by many systems and offer compatibility.
- Simplifies Transport of data – transport of data from one platform to another.
- Simplifies Platform Changes – Easy to upgrade systems as the new platform will have no issue reading XML.
- Makes data more available – Multiple applications can access the same XML data.
- Can Create new internet languages – XHTML, WSDL, RSS, RDF… These use XML in some way.
- Important XML Rules
- All tags must have an opening and close tags (unlike HTML tags such as
) .In XML closing of tag is compulsory. You can write br tag in HTML but in XML you need to write it as
XHTML1<br/> or <br></br>
- Tags in XML are case sensitive –
is not the same as .
- Elements need to be nested properly. If you open the user tag i.e. the child element in the document structure shown above, and close any sub-child element after the closing of the user tag, it will be an error.
- XML documents must have a root element. There can only be one instance of a root element.
- Attributes must be quoted.
- XML Schemas
- All XML Schema describes the structure of an XML document.
- The schema describes the allowed data, required data and how the data should be organized.
- Types of schemas are:
- DTD – Document Type Definition.
- XML Schema – XSD, RELAX NG, W3C XML Schema language. These are the different versions of XML Schemas.
- XML has a certain schema that an XML file has to match up against in order to be comparable.
Now let’s see the basic document structure of XML file in this XML Fundamentals tutorial.
<?xml version = “1.0” encoding=”UTF-8”?> ----Declaration
<users> --------------------------------Root Element
<user> ----------------------------Child Element
<phone>555-555-5555</phone> ------ Elements
This was a short introduction to XML Fundamentals.