Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Modifying XML with javascript or PHP


  • Please log in to reply
5 replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:03:31 PM

Posted 19 April 2009 - 04:36 AM

I have a .xml file with this contents:

songs.xml
<?xml version="1.0" encoding="UTF-8"?>
<xml>
	<track>
		<path>songs/song1.mp3</path>
		<title>song 1</title>
	</track>
	<track>
		<path>songs/song2.mp3</path>
		<title>song 2</title>
	</track>
	<track>
		<path>songs/song3.mp3</path>
		<title>song 3</title>
	</track>
	<track>
		<path>songs/song4.mp3</path>
		<title>song 4</title>
	</track>
</xml>

i have a flash player that views that list and displays the content in that order. I'm wanting to make a shuffle button that when clicked, uses javascript or php to shuffle each <track> ... </track> tag.

Is this possible?

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:31 PM

Posted 19 April 2009 - 12:00 PM

Yes.

#3 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:03:31 PM

Posted 19 April 2009 - 05:47 PM

where would i start? what server/client side processing would i use? My research suggests using php to do it.

No idea how to though.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:31 PM

Posted 19 April 2009 - 06:04 PM

You can do it client side with PHP, or you could do it server side with javascript. All you really have is a list, or a collection of songs, so on the javascript side, you could simple create an array of all of the songs, then randomize it. Randomizing arrays is a bit tricky if you have never done it. Here is a pretty clean way to do it.

On the server side, you would do pretty much the same thing, except that once you had a randomized 1st, then you would create an XML file from the randomized array.

In any case, the first thing you would do is to figure out how to get the stuff that needs to be sorted out of the XML. This is called XML parsing, and you can write your own, are probably find a library somewhere that will do it for you. Once you are able to extract the objects to shuffle, then you randomize their order. Once you are able to do that, then you need to figure out some way to put it into a readable order.

This is a multi-step process that you want to create and not something that you are going to do in 5 lines of code. Maybe 150. Maybe more, maybe less. There should be tons of available examples to help you handle each part.

Gotta go now; I have a bug I process that I have been trying to figure out for the last three days. :thumbsup:

#5 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:03:31 PM

Posted 19 April 2009 - 10:07 PM

Trouble is i don't know how to create an array let alone randomise one.

I've tried googling it, but most of the tutorials jump straight into complex equations. Am i randomising strings?

Any basic array tutorials would be great!

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:31 PM

Posted 20 April 2009 - 07:31 AM

http://www.phphelps.com/7_Creating_and_loo...ay_in_PHP.shtml
http://www.tizag.com/phpT/arrays.php

http://www.hunlock.com/blogs/Mastering_Javascript_Arrays


Arrays are a difficult concept to understand at first. Once a persone understands what they are, then they are easier to program to.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users