XML is a very important base on which Web Services work. XML can be used in conjunction with a lot of client side and server side languages to put it to good use.
Sample XML file:
Let us consider a sample XML file >>
<?xml version="1.0" ?>
<employee id="001" sex="M" age="19">Premshree Pillai</employee>
employee id="002" sex="M" age="24">Kumar Singh</employee
<employee id="003" sex="M" age="21">Ranjit Kapoor</employee>
The above XML file shows employee data and Turnover of the company (just an e.g).
verify() is called.
Now the XML file can be loaded
- Displaying contents of XML file: View the entire contents of the XML file using alert(xmlObj.xml);
The entire XML file will be displayed in an alert box as it is with proper indentation.
- Children and nodes: In the above XML file <company> is the top level tag under which all other tags come. These tags are called children. The above XML file can be represented graphically like a folder-tree. A folder-tree is shown below.
| Thus in the above XML file the top level tag
The numbering of children (as is usual in all languages) starts from 0 (zero).
We can find the no of children a tag has by using the
The no of children of
- Testing for children: You can test whether a particular node child has any children using
xmlObj.childNodes(3).hasChildNodes()will return true.
xmlObj.childNodes(2).hasChildNodes()will return false, since the
<employee>tag does not have any children.
- Getting Tag Name: You can get the tag name of a child using
xmlObj.tagNamewill return “company”.
xmlObj.childNodes(0).tagNamewill return “employee”.
xmlObj.childNodes(3).childNodes(0).tagNamewill return “year”.
- Displaying content of a tag: In the XML file the content of the 1st
<employee>tag is “Premshree Pillai”. You can get this value using
xmlObj.childNodes(2).firstChild.textwill return “Suhasini Pandita”.
xmlObj.childNodes(3).childNodes(1).firstChild.textwill return “140,000”.
- Attributes: In the XML file, the
<employee>tag has 3 attributes. An attribute can be accessed using
xmlObj.childNodes(0).getAttribute("id")will return “001”.
xmlObj.childNodes(1).getAttribute("age")will return “24”.
xmlObj.childNodes(2).getAttribute("sex")will return “F”.
The structure of the XML document is as follows >>
tickerstyle >> pause = "true" / "false" :: "true" for pause onMouseOver >> timeout = any integer :: The delay in seconds between different messages. >> border = any integer :: Border width of Ticker >> bordercolor = #HexColor :: The border color of Ticker >> background = #HexColor :: Background color of Ticker >> width = any integer :: Ticker width >> height = any integer :: Ticker height tickerlinkstyle mouseout >> font = "verdana,arial,helvetica....." :: Ticker link font >> color = #HexColor :: Ticker link color >> decoration = "none" / "underline" / "underline + overline" :: Ticker link style >> weight = "normal" / "bold" :: Ticker link weight >> size = 'any integer'pt :: Ticker link size mouseover >> font = "verdana,arial,helvetica....." :: Ticker link font >> color = #HexColor :: Ticker link color >> decoration = "none" / "underline" / "underline + overline" :: Ticker link style >> weight = "normal" / "bold" :: Ticker link weight >> size = 'any integer'pt :: Ticker link size tickeritem >> URL = A valid URL :: Ticker link URL >> target = "_blank" / "_top" / "_self" / 'any other valid target name' :: Ticker link target
XML Ticker Script :
As you can see in the source code, the ticker reads all the contents/messages to be displayed, the links for each message, the target for each URL, the ticker static style, roll-over style, border width, color, background, the delay between messages etc from the XML file. So if you want to change any parameter of the Ticker, all you have to do is make necessary changes in the XML file.
The ticker shown here is a basic ticker that rotates messages at an interval that is specified in the XML file. There are many effects you could add to the ticker like Fading message, Teletypewriter. You could add features to change the ticker speed or to list all messages at an instant.
I hope this article has helped you in some way.
Article first appeared at CodeToad. Reprinted with the author’s permission.
Premshree Pillai studies engineering in Information Technology at
Mumbai University, Mumbai, India. He is a programming enthusiast
and maintains a Website (http://www.qiksearch.com), where he posts
his scripts. He is also a freelance writer and has written for a
range of popular Indian magazines.