Monday, February 17, 2014

Simple Example Book.xml

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new society.</description>
   </book>
   <book id="bk104">
      <author>Corets, Eva</author>
      <title>Oberon's Legacy</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-03-10</publish_date>
      <description>In post-apocalypse England, the mysterious 
      agent known only as Oberon helps to create a new life 
      for the inhabitants of London. Sequel to Maeve 
      Ascendant.</description>
   </book>
   <book id="bk105">
      <author>Corets, Eva</author>
      <title>The Sundered Grail</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2001-09-10</publish_date>
      <description>The two daughters of Maeve, half-sisters, 
      battle one another for control of England. Sequel to 
      Oberon's Legacy.</description>
   </book>
   <book id="bk106">
      <author>Randall, Cynthia</author>
      <title>Lover Birds</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-09-02</publish_date>
      <description>When Carla meets Paul at an ornithology 
      conference, tempers fly as feathers get ruffled.</description>
   </book>
   <book id="bk107">
      <author>Thurman, Paula</author>
      <title>Splish Splash</title>
      <genre>Romance</genre>
      <price>4.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>A deep sea diver finds true love twenty 
      thousand leagues beneath the sea.</description>
   </book>
   <book id="bk108">
      <author>Knorr, Stefan</author>
      <title>Creepy Crawlies</title>
      <genre>Horror</genre>
      <price>4.95</price>
      <publish_date>2000-12-06</publish_date>
      <description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
   </book>
   <book id="bk109">
      <author>Kress, Peter</author>
      <title>Paradox Lost</title>
      <genre>Science Fiction</genre>
      <price>6.95</price>
      <publish_date>2000-11-02</publish_date>
      <description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems 
      of being quantum.</description>
   </book>
   <book id="bk110">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in 
      detail in this deep programmer's reference.</description>
   </book>
   <book id="bk111">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in 
      detail, with attention to XML DOM interfaces, XSLT processing, 
      SAX and more.</description>
   </book>
   <book id="bk112">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <genre>Computer</genre>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
   </book>
</catalog>

Tuesday, February 4, 2014

Rules for naming in XML

XML elements must follow these naming rules:

  •     Names can contain letters, numbers, and other characters
  •     Names must not start with a number or punctuation character
  •     Names must not start with the letters xml (or XML, or Xml, etc)
  •     Names cannot contain spaces

Though no words are reserved for naming, and you can use any letters, numbers for a name, but a good naming practice should be:
   1) Make names descriptive. For example: <firstname>,<lastname>.
   
   2)  For separate words, You may use an underscore: <table_size>. Avoid use dash "-", dot ".", and colon ":". If you name something "table-size", or "table.size", or "table:size", some software may misunderstand it.
   
   3)  Keep a name short and simple, like: <city_name>. Do not use a name like this: <the_name_of_the_city>.
   
   4)  If you need to use non-English letters like ¨¦¨°¨¢ in XML, your should check with the software vendor to find out if it supports them.

XML Syntax(2)

XML documents must contain one element that is the parent of all other elements. That element is called the root element.

Syntax:-

    <root>
        <child>
            <subchild>.....</subchild>
        </child>
    </root>

XML Attribute Values Must be Quoted.

XML elements can have attributes in name/value pairs just like in HTML. But in XML the attribute value must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct:

    HTML -->    <design style=bold>

    XML --->    <design style="bold">

Some characters have a special meaning in XML.

If you place a character like "<" inside an XML element, for example:

    <category> Mahi has < rs.10000 </category>

The character "<" will generate an error because the parser interprets it as the start of a new element. To avoid this error, replace the "<" character with an entity reference:

<category> Mahi has &lt; rs.10000</category>

There are 5 predefined entity references in XML:

    &lt; < less than
    &gt; > greater than
    &amp; & ampersand
    &apos; ' apostrophe
    &quot; " quotation mark

Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.

Comments in XML. The syntax for writing comments in XML is the same as in HTML.

<!-- This is a comment -->

In XML, White Space is Preserved. In an HTML file, multiple white space characters are reduced to a single white space. But in an XML file, the white space is not truncated.

XML Syntax(1)

Rules for the syntax of XML:
  • A XML document must contain a pair, and only a pair, of root tags
  • All XML elements must have a opening tag and a closing Tag.
  • XML tags are case sensitive.
  • An element in XML can has its child element.
  • All elements in XML must be properly nested within each other.
  • XML attribute values must be quoted.

As you know, HTML is quite forgiving when it comes to tag placement, missing tags, and attribute values. For ex:- A web browser  will correctly interpret an HTML page even if you forget to put a closing tag, like :-
<p>I am MaHi.
<li>I iive in surat.
In XML, all elements must have a closing tag:
<p>I am MaHi</p>
<li>I live in surat</li>
In HTML, tags are not case sensitive. you can use a tag like "<head>", or "<Head>", or "<HEAD>". They all are valid. But in XML, "<head>", or "<Head>", or "<HEAD>" will be three different tags because XML Tags are case sensitive. So you must write your opening and closing tags with the same case:
<HEAD>This is incorrect</head>
<head>This is correct</head>
In HTML, even the elements are improperly nested, it may still work.:
<b><i>Bold with Italic</b></i>

XML Elements Must be Properly Nested:
<b><i>Bold with Italic</i></b>

Formate and Structure of XML(2).

XML documents must contain one element that is the parent of all other elements. This element is called the root element.


Syntax:

<root>
<child>
<subchild>.....</subchild>
</child>
</root> 


XML elements can have attributes in name/value pairs just like in HTML. But in XML the attribute value must always be quoted.

For ex:-
1) this one create erore.
 
<info birthday=05/01/1991>
<firstname>Mahi</firstname>
<lastname>Babariya</lastname>
</customer> 


2) this one is right 


<info birthday="05/01/1991">
<firstname>Mahi</firstname>
<lastname>Babariya</lastname>
</customer>

Formate and Structure of XML(1).

A XML document is consist of tags and data. All data in an XML document is wrapped by the tags.

Here is the example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<student>
<firstname>Mahi</firstname>
<lastname>Babariya</lastname>
<gender>male</gender>
<address>
<street>147, Parle point</street>
<city>Surat</city>
<state>Gujarat</state>
<zip>395007</zip>
<country>India</country>
</address>
<phone>99887766555</phone>
<email>mahi@yahoo.com</email>
</student>

The first line is the XML declaration. It defines the XML version (1.0) and the character set (ISO-8859).
The next line uses tag "<customer>". It is the root element of the document.
The next four lines describe the child elements () of the root.
Please note that, except the first line, all tags in the document are used in pair: opening tag and closing tag.
you can assume the structure of an XML file as a "tree" that starts at the root tag "student" and branches to the leaves tags "firstname", "lastname", "gender", "address", "phone" and "email".

Please note, an XML document must contain a pair of root tags for the "parent" element, whcih contains all other elements. You cannot have two roots in a single XML document. All elements can have child elements.

XML Introduction

XML stands for EXtensible Markup Language, which became a W3C Recommendation on 10. February 1998.

XML is a markup language which is like HTML. XML and HTML both use tags. But there are some differences between them :
1) HTML was designed for how to display data. And XML was designed for how to store data.
2) HTML tags are predefined (for example "<p>", "<table>", etc.). But XML tags are not predefined. You must define your own tags

XML can be used to simplify data storage and sharing. With XML, data is separated from HTML. So you can create HTML layouts for displaying data. When the data changes, you don't have to recreate your HTML file. With XML, data can also be easily exchanged between computer and database systems, even they are incompatible in any other ways. Because XML data is stored in text format, this makes it easier to export data from a system to an XML file, and then import it into another system. Before we have XML, the task of exchanging data between incompatible systems was not easier and complicated due to the different data formats. Now XML greatly reduces this complexity, and we can be easily expand or upgrade our operating systems and applications without losing data.