What is XML?

The name XML comes from the full name of the language, Extensible Markup Language. Although markup is in the name of the language, do not think XML as you do HTML because, aside from the fact that both languages are based on tag pairs, there are no similarities. XML is used for storage and exchange of data within its tag pairs, whereas HTML couldn’t care less what is contained in the content and how it is structured-­ its only purpose is to display the content to the browser. In other words, XML defines and carries the content, whereas HTML makes it visually appealing to the reader.

Basic XML Document Structure

Xml documents contain two major elements, the prolog and the body. The prolog contains the XML declaration statement, and any processing instructions and comments you want to add.

The following snippet is a valid prolog

<? Xml version=”1.0” ?>

<! .. Sample XML document ..>

After the prolog comes the content structure. XML is hierarchical, like a article- articles have titles and chapters, each of which contain paragraphs, and so forth. There is only one root element in an XML document. Continuing the example, the element might be called article, and the tags<article></article> surround all other information.

<articles>

Next, add any subsequent elements-called children-to your document. Continuing the article example, You need a master article element then within its elements for title, author, and publishing information. Call these child elements TITLE, AUTHOR, and PUBLISHINGINFO. But the publishing information will likely contain more than one bit of information- you’ll need a publisher’s name, location, and year of publication. Not a problem-just creates another set of child elements within your parent element (which also happens to be child elements of the root element). For example, just the<PUBLISHINGINFO>element could like this:

<publishinginfo>

<publisherName>sams Publishing</publisherName>

<publishercity>Indianapolis>/publishercity>

<publishedyear>2008</publishedyear>

</publishinginfo>

All together, a sample article .xml document withone entry could look something like this :

<?XML version=”1.0” ?>

<!..Sample XML document ..>

<articles>

<article>

<Title>A very good article</Title>

<Author>Jane Doe</Author>

<publishinginfo>

<publisherName>sams Publishing</publisherName>

<publishercity>Indianapolis>/publishercity>

<publishedyear>2008</publishedyear>

</publishinginfo>

</article>

</articles>

 

Keep in mind two important rules for creating valid XML documents

  • XML is case sensitive, so <Article> and <article> are considered different elements.
  • All XML tags must be properly closed, XML tags must be properly nested, and no overlapping tags are allowed.

Written by Ranjeet Jha

Ranjeet Jha

Hey there! My name is Ranjeet. I’m a Web Designer & Front-end Developer. I design, code, build & promote all things HTML5, CSS3, JavaScript & jQuery. In this blog you will find solutions of day to day problems faced by you.. Enjoy Coding..

Leave a Reply

Your email address will not be published. Required fields are marked *