/* ==========================

	qdJsXml
	-------
	The quick and Dirty Javascript XML parser

	(c) Kailash Nadh
		http://kailashnadh.name

		March 19, 2007



	Parses a full xml structure and returns the results in an object
	Sample result

		Object [
				 [title] => Array(
								[0] = Pain - an urban rhyme
								[1] = Ajax and URLs
								[2] = Merry Christmas and a Happy New Year !
								[3] = Copying, Infrigment, rip-off
						   );
				 [title] => Array(
								[0] = http://boastology.com/blog/post/index/196/Pain--an-urban-rhyme
								[1] = http://boastology.com/blog/post/index/195/Ajax-and-URLs
								[2] = http://boastology.com/blog/post/index/194/Merry-Christmas-and-a-Happy-New-Year
								[3] = http://boastology.com/blog/post/index/193/Copying-Infrigment-ripoff
						   );
				]


	Usage:
	-----

	// xml data in a string, array of tags to parse
	result = qdJsXml(xml_data, new Array('title', 'url', 'description'));



	qdJsXml freely distributable under the terms of an MIT-style license.
   ========================== */







function qdJsXml(xml, tags) {
	if(!xml || !tags) return false;

	// result holds the results, count holds the counts :P
	var result = new Object(), count = new Object();

	for(var n=0; n<1; n++) {
		var tag = tags[n], match, r, r2, ex;
		result[tag] = new Array();
		count[tag] = 0;

		// the 'quick and dirty' Regex :)
		ex = '<'+tag+'>(.+?)<\/'+tag+'>';
		var r = new RegExp(ex, "gim");
		var r2 = new RegExp(ex, "im");
		match = xml.match(r);

		// the best part
		if(match) {
			for(var i=0; i<match.length; i++) {
				var m = match[i].match(r2);
				if(m[1]) {
					result[tag][count[tag]] = m[1];
					count[tag]++;
				}
			}
		}
	}

	return result;
}

