1.Writing an XML document

/* Click here to see a list of all XML tutorials */

Q   Why XML why not directly write to a  Database file ?
Ans

  1. .XML can be written in a simple text file which not only makes it portable but also easily accessible.
  2. Other Databases like MS Access, SQL (though they provide a nice user friendly interface ) require  to be installed before they can  be used. Consider for eg I saved a file in MSAccess(.mdb) and shiffted to a Linux system which does not have support for that file so it proves useless. If instead I can use xml and store it in a plain text file,then I could view ,edit and store it.
  3. XML requires  simple text editor , and hence can be used over all most all platforms even older OS’s
  4. IT is easy to decode XML data and using some common sense it can be used in any programming language to display Data.

One way of understanding XML is to view it as a Tree structure represented in text format

xml eg

Consider the above diagram.

The company is the root

The company has a  child nodes -Employee
Employee has child nodes -Name and Post
The company has another child nodes -Employee2
Employee2 has child nodes -Name and Post

Now we represent it in XML in a similar  way
Here each node becomes an Element.
(Remeber the elements are case sensitive)

<company>       <!-under this  company we   have…..–>

<!– for first employee–>
<employee>  <!- under employee we have…..>
<name>Jack</name>
<post>Manager</post>
<employee>  <!– that its for  1st employee–>

<!– for second employee–>
<employee>  <!- under employee we have…..–>
<name>John</name>
<post>CEO</post>
<employee>  <!– that its for  2nd employee–>

</company><!– thats it for company–>

Now that we have the basic  understanding we’ll learn how to implement it.

We also have to mention the XML version we are using ,

eg.  <?xml version=”1.0″ encoding=”ISO-8859-1″?>

hence we have our final XML syntax file

company.xml

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<company>
<employee>
<name>Jack</name>
<post>Manager</post>
<employee>
<company>
<employee>
<name>John</name>
<post>CEO</post>
<employee>
</company>

HopeThisHelps
Roy
/* Click here to see a list of all XML tutorials */

DidYouKnow???

What’s the farthest computer from Earth?
NASA’s Voyager satellite computes at the edge of space as we know it, which, BTW, has passed by Jupiter and Saturn – and it’s almost 30 years old.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.