function XMLWriter()
{
	this.XML=[];
	this.Nodes=[];
	this.State="";
	this.LevelIndent = "";
	this.FormatXML = function(Str)
	{
		if (Str)
			return Str.replace(/&/g, "&amp;").replace(/\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
		return ""
	}
	this.BeginNode = function(Name, Level)
	{
		this.LevelIndent = "";
		while (Level > 0)
		{
			this.LevelIndent = this.LevelIndent + "  ";
			Level = Level -1;
		}
		if (!Name) return;
		if (this.State=="beg") this.XML.push(">");
		this.State="beg";
		this.Nodes.push(Name);
		this.XML.push(this.LevelIndent+"<"+Name);
	}
	this.EndNode = function(Level)
	{
		this.LevelIndent = "";
		while (Level > 0)
		{
			this.LevelIndent = this.LevelIndent + "  ";
			Level = Level -1;
		}
		if (this.State=="beg")
		{
			this.XML.push("/>");
			this.Nodes.pop();
		}
		else if (this.Nodes.length>0)
			this.XML.push(this.LevelIndent+"</"+this.Nodes.pop()+">");
		this.State="";
	}
	this.Attrib = function(Name, Value)
	{
		if (this.State!="beg" || !Name) return;
		this.XML.push(" "+Name+"=\""+this.FormatXML(Value)+"\"");
	}
	this.WriteString = function(Value)
	{
		if (this.State=="beg") this.XML.push(">");
		this.XML.push(this.FormatXML(Value));
		this.State="";
	}
	this.Node = function(Name, Value, Level)
	{
		this.LevelIndent = "";
		while (Level > 0)
		{
			this.LevelIndent = this.LevelIndent + "  ";
			Level = Level -1;
		}
		if (!Name) return;
		if (this.State=="beg") this.XML.push(">");
		this.XML.push((Value=="" || !Value)?this.LevelIndent+"<"+Name+"/>":this.LevelIndent+"<"+Name+">"+this.FormatXML(Value)+"</"+Name+">");
		this.State="";
	}
	this.Close = function()
	{
		while (this.Nodes.length>0)
			this.EndNode();
		this.State="closed";
	}
	this.ToString = function(){return this.XML.join("");}
}
