SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is This Possible Using Javascript?

    I have a text banner that is very boring. It says the same thing over and over again.

    EXAMPLE:

    Download Kanye West's All Falls Down To Your Cellphone!

    Ideally, I'd like it to have random sayings. Like:

    Download $x's $y To Your Cellphone!

    So, as of now, I have an XML file that contains the information I'd like the banner to say. [http://www.sohh.com/xml/ringtone_banners.xml] I'd like to use this XML file as is, considering that it powers a jukebox.

    Where would I start to create something like this? or is this just not possible?
    <///////~

    www.sohh.com

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you now incorporating the XML into your web site?

  3. #3
    SitePoint Addict ibeblunt's Avatar
    Join Date
    Jan 2001
    Location
    Jersey City, NJ
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The XML is feeding a Flash Application on my site.
    <///////~

    www.sohh.com

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With MSIE you can use ms XML tag and DOM to access your xml file:

    Code:
    <xml id=songs src="http://www.sohh.com/xml/ringtone_banners.xml"/>
    
    <script>
    var messageTemplate = "Download <a href={url}>{title}</a> by {artist}";
    
    function getRandomSong() {
    	var media = songs.selectSingleNode("*/media");
    	var song  = media.childNodes[Math.floor(Math.random()*media.childNodes.length)];
    	var message = messageTemplate.replace(/\{(\w+?)\}/g,
    		function($0, $1){
    			return song.selectSingleNode($1).firstChild.nodeValue
    		}
    	);
    	alert(message);
    } 
    </script>
     
    <button onclick="getRandomSong()"></button>
    No idea how to make this in mozilla.

  5. #5
    SitePoint Zealot tss68nl's Avatar
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mozilla can read XML as well, but it's a bit bloated (about 2 19" screens of code). I'd say for this low volumes of data you are better off creating a makeshift parser for the xml file yourself. Just read it as a text file, and use regular expressions to get the data out. With the right expression, you can get all your data with just one match, which is prolly even less code than the xml way in IE.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •