Have a close look at the above multiple namespace example … we define two namespaces one is for book element and another is for author element .. however you can use use the namespace of book element in the language element but you can’t use the namespace of author into any other elements that are not descendant of author …
In this tutorial i am gonna talk about xml namespace scope … you may read about variable scope in c or c++ language .. however in xml namespace also have some scope ..
That is when you define an xml namespace for an element it will only work for that element and its contained descendants, this is know as the defined namespaces working area .. it does not work if you prefix the same namespace for another element or child that is not within the element where we defined the namespaces .. Look at the below example .. <?xml version=”1.0″ encoding=”ISO-8859-1″?>
Hey welcome back again … in this tutorial i will discuss about xml namespace .. As you know xml offer you to create your own elements or tags whatever you say .. so for this during the time you create a lot of element in lot of xml files a confliction between the elements name easily occur .. To remove this confliction xml also offer you to define namespaces ..
Lets see an example …
<title>The mind freak</title>
Now you have this two xml files and Suppose somehow you have combine this two xml files … when you do this an error will show up to you because magician and bookstore element both contain a descendant named title ..
In this part of tutorial i will define some words that may come in front of you many times during xml coding … those are
Before i make a description of those lets create a xml code …
well in this code … <grand_parents>,<parents> are ancestor cause they have descendants .. that means <grand_parents> contains two other element and <parents> also contains elements .. but <me> and <my_brother> are not ancestor cause they does not contain any element
Again ,, <parents> and <me> and <my_brother> are descendant cause they have a root/parents …
One think you may notice that <parents> is also a descendant and ancestor .. cause <parents> have child and parent ..
— Siblings are <me> and <my_brother>
— parent are child are too much easy to understand .. they are in regular meaning …
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<?xml-stylesheet type=”text/css” href=”3.css”?><!–This is how we connect to css file–>
/****************** 3.css **************/
/* CSS Document */
font-family:”Comic Sans MS”, cursive;
# Every xml code must have root element or document ..
# Each opening tags must have it closing tag ..
# Attributes values must be quoted ..
# Use entities for the replacement of those <,>,&,’,” signs cause those signs may change the meaning of the syntax ..
# XML is case sensitive.. <tag> and </Tag> execute as two different tag ..
# Unlike HTML XML does not truncate white spaces ..
# It also stores Line feed and Carriage return ..
Remember all those stuff that will help u out in xml coding ..
<?xml version=”1.0″ encoding=”utf-8″?>
<name>Teach Yourself C</name>
<name>Teach Yourself C++</name>
This is how to comment on XML .. same as HTML comment ..
This is a example of Basic syntax how to write XML code … the tag <booklist> is called the root … and remain tags are called child of the root tag ..
How save and show and XML code :
At first open up a notepad/wordpad then write this code changed the file name into anything but do not forget to change extension into .xml .. Now open it into your browser that will show the same code as well cause it is xml .. its only store the data …
XML ..!! That stands for eXtensible Markup Language … Why its called extensible !! the reason is is that xml gives the programmer freedom to write his tag .. impressive isn’t it? .. yes it is .. as you are a html coder you know how to define tags, attributes, entity etc … all these things are also in XML ..
Then a question may be rise in your head that if almost all the things are same as html then why should we learn XML .. well, first i will say XML is not a complement of HTML ..
Difference between XML and HTML are …
XML deals only with data .. like stroing data, transmission data etc .. but it does not show any data or some contents of a page ..
On the other hand, HTML deals how to show data or page content to a user .. it does not deals with data storing or transmission ..
Lets see how we can find it useful :
# XML reduce the data redundancy by storing data ..
# As it store data so we can show those data in varius styles in different section of web pages ..
# XML supports other language as well ..
At last i m gonna say it is a simple language to learn(as far as i know), then what is the problem to learn it and keep going … 🙂