//$Id: xmlparse.js,v 1.5 2008/01/18 18:06:16 steve Exp $
//a file for parsing very basic xml
function Node(name,value) {
	this.nodeName=name;
	this.nodeValue=value;
}

function subTree() {
	var nodeList=new Object();
	var i=0;
	while (this.cursor<this.source.length) {
		var start=this.cursor;
		var tagStart=this.source.indexOf('<',this.cursor);
		if (tagStart==-1) {
			return nodeList;
		}
		var tagEnd=this.source.indexOf('>',tagStart);
		this.cursor=tagEnd+1;
		var tag=this.source.substr(tagStart+1,tagEnd-tagStart-1);
		if (tag.charAt(0)!='?') {
			if (tag.charAt(0)!='/') { // found end tag
				nodeList[i++]=new Node(tag,this.subTree());
			}else{
				if (i==0){ // no child-elements, there was chardata
					return this.source.substr(start,tagStart-start);
				}else{ // found start tag, parse childnodes
					return nodeList;
				}
			}
		}
	}
	return(nodeList);
}

function rpcXMLDocument(source) {
	this.subTree=subTree;
	this.source=source;
	this.cursor=0;
	this.dom=this.subTree();
	this.params = [];
	this.tmpnode = this.dom[0].nodeValue[0].nodeValue;
	for (this.i in this.tmpnode) {
		try{
			this.params[this.i] = unescape(this.tmpnode[this.i].nodeValue[0].nodeValue[0].nodeValue);
		}catch(err){
			//nothing
		}
	}
	
}

