Article

Using the XML Data Source Object

Page: 1 2 3

XML Ticker Using XML-DSO

So far we’ve considered simple examples. Now, we’ll look at a more dynamic example: "XML Ticker using XML-DSO". In this example, the ticker reads its messages and URLs from an external example file, and ticks the messages with a specified delay.

<!-- ticker.xml -->  
<?xml version="1.0" ?>  
<ticker>  
 </item>  
 <item>  
   <message>JavaScripts by Premshree Pillai</message>  
     <URL>http://premshree.resource-locator.com/  
javascripts.htm</URL>  
 </item>  
 <item>  
   <message>The Scripting Newsletter</message>  
     <URL>http://premshree.resource-locator.com/cgi-bin/  
newsletter.pl</URL>  
 </item>  
</ticker>  
 
<!-- ticker.css -->  
.tickerStyle {  
 font-family:verdana,arial,helvetica; font-size:10pt;    
color:#666666;    
border:#666666 solid 1px; width:400px; height:20px;    
text-decoration:none; text-align:center;  
background:#FFFFFF  
}  
.tickerStyle:hover {  
 font-family:verdana,arial,helvetica; font-size:10pt;    
color:#FF6600;    
border:#666666 solid 1px; width:400px; height:20px;    
text-decoration:none; text-align:center;  
background:#FFFFFF  
}  
<!-- ticker.htm -->  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
<html>  
<head>  
<title>XML Ticker using XML DSO</title>  
<link rel="stylesheet" href="ticker.css">  
 
<!-- begin script -->  
<script language="JavaScript">  
//////////////////////////////////////////////////  
//  XML Ticker using XML DSO    //  
//////////////////////////////////////////////////  
 
var xmlDso, tickerSet;  
function initTicker(xmlFile, objName, counter, maxMsgs, timeOut) {  
 /* Check for IE4+ */  
 if(document.all&&navigator.userAgent.indexOf("Opera")==-1) {  
   eval('xmlDso='+objName+'.XMLDocument');  
   xmlDso.load(xmlFile);  
   setTimeout("xmlDsoTicker('"+objName+"','"+counter+"',  
'"+maxMsgs+"',  
'"+timeOut+"')", timeOut);  
 }  
 else {  
   alert('This Ticker works with IE4+ only!');  
   return false;  
 }  
}  
 
function xmlDsoTicker(objName, counter, maxMsgs, timeOut) {  
 /* Get all the data as a record set */  
 eval('tickerSet=' + objName + '.recordset');  
 if(!tickerSet.EOF && counter<maxMsgs-1) {  
   tickerSet.MoveNext();  
   counter++;  
 }  
 else {  
   counter=0;  
   tickerSet.MoveFirst();  
 }  
 setTimeout("xmlDsoTicker('"+objName+"','"+counter+"',  
'"+maxMsgs+"',  
'"+timeOut+"')", timeOut);  
}  
</script>  
<!-- end script -->  
</head>  
 
<body bgcolor="#FFFFFF">  
 
 <!-- begin ticker placement -->  
 <center>  
 <object id="ticker" CLASSID="clsid:550dda30-0541-11d2-9ca9-  
0060b0ec3d39" width="0"  
height="0"></object>  
 <a href="" datasrc="#ticker" datafld="URL"  
class="tickerStyle">  
   <span datasrc="#ticker" datafld="message"></span>  
 </a>  
 <script language="JavaScript">  
 var tickerMaxMsgs=2; // Maximum Messages in the XML Data file  
 var tickerCount=tickerMaxMsgs;  
 new initTicker("ticker.xml","ticker",tickerCount,tickerMaxMsgs,2000);  
 </script>  
 </center>  
 <!-- end ticker placement -->  
 
</body>  
</html>

Here's how the output appears:

1121_image3

Before you go, don't forget to download all the examples we covered in this article!

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: