BleepingComputer.com: Modifying XML with javascript or PHP

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.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Modifying XML with javascript or PHP

#1 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

  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?
If I am helping you and don't reply in 24 hours please send me a PM

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.

#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 19 April 2009 - 12:00 PM

Yes.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#3 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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.
If I am helping you and don't reply in 24 hours please send me a PM

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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:
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#5 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 548
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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!
If I am helping you and don't reply in 24 hours please send me a PM

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users