XML.newDocument = function(rootTagName, namespaceURL) {
	
	// set defaults
	if (!rootTagName) rootTageName = "";
	if (!namespaceURL) namespaceURL = "";
	
	if (document.implementation && document.implementation.createDocument) {
	
		// W3C standard way to do this
		return document.implementation.createDocument(namespaceURL, rootTagName, null);
	
	} else {
		
		// Create an empty docment as an ActiveXObject
		// If there is no root element, this is all we have to do
		var doc = new ActiveXObject("MSXML2.DOMDocument");
		
		// if there is a root tag, initialize the element
		if (rootTagName) {
			
			// look for a namespace prefix
			var prefix = "";
			var tagName = rootTagName;
			var p = rootTagName.indexOf(':');
			
			if (p != -1) {
				prefix = rootTagName.substring(0, p);
				tagName = rootTagName.substring(p+1);
			}
			
			
			// if we have a namespace, we must have a namespace prefix
			// if we don't have a namespace, we discard any prefix
			if (namespaceURL) {
				
				if (!prefix) prefix = "a0"; // what Firefox uses	
			
			} else {
				prefix = "";
			}
			
			// create the root element (with optional namespace) as a string of text
			var text = 
				"<" + 
				(prefix ? (prefix+":") : "") +
				tagName + 
				(namespaceURL ? (" xmlns:" + prefix + '="' + namespaceURL + '"') : "") 
				+ "/>";
				
			// parse the text into an empty document
			doc.loadXML(text);
			
		}
		
		return doc;

	}
	
};

XML.load = function(url) {
	
	var xmldoc = XML.newDocument();		// Create a new document with the previously defined function
	
	xmldoc.async = false;				// load synchronously; runs asynchronously by default
	xmldoc.load(url);					// load and parse
	
	return xmldoc;						// return the xml document object
	
};

//XML.parse = function(text) {
//	
//	if (typeof DOMParser != "undefined") {
//		
//		// Mozille, Firefox, and related browsers
//		return (new DOMParser()).parseFromString(text, "application/xml");
//	
//	}
//	else if (typeof ActiveXObject != "undefined") {
//		
//		// Internet explorer
//		var doc = XML.newDocument();	// create an empty doc
//		doc.loadXML(text);				// parse text into it
//		
//		return doc;						// return the new doc
//		
//	}
//	else {
//		
//		// As a last resort, try loading the document from a data: URL
//		// supposedly works in Safari
//		var url = "data:text/xml;charset=urf-8," + encodeURIComponent(text);
//		var request = new XMLHttpRequest();
//		
//		request.open("GET", url, false);
//		request.send(null);
//		
//		return request.responseXML;
//		
//	}
//	
//};