function createXMLDocument(rootElementName)
{
	var xmlDocument = null;
	
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDocument = document.implementation.createDocument('', rootElementName, null);
	}
	else if (typeof ActiveXObject != 'undefined')
	{
		try
		{
			xmlDocument = new ActiveXObject('Microsoft.XMLDOM');

			var rootElement = xmlDocument.createNode(1, rootElementName, '');
			xmlDocument.appendChild(rootElement);
		}
		catch(e)
		{
		}

	}
	if ((xmlDocument.documentElement == null) && (xmlDocument.createElement))
	{
		root = xmlDocument.createElement(rootElementName)
		root.appendChild(xmlDocument.createTextNode(' '));
		xmlDocument.appendChild(root);
	}
	return xmlDocument;
}

function createXMLFromString(string)
{
	var xmlDocument;

	if(typeof DOMParser != 'undefined')
	{
		try
		{
			var domParser = new DOMParser();
			xmlDocument = domParser.parseFromString(string,"text/xml");
		}
		catch(e)
		{
			xmlDocument = null;
		}
	}
	else
	{
		try
		{
			xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
			xmlDocument.async = false;
			xmlDocument.loadXML(string);
		}
		catch(e)
		{
			xmlDocument = null;
		}
	}
	
	return xmlDocument;
}

function AppendXmlNode(xmlDoc, appendToNode, nodeName, nodeText)
{
	if (nodeText && (nodeText != ""))
	{
		var node = xmlDoc.createElement(nodeName);
		node.appendChild(xmlDoc.createTextNode(nodeText));
		appendToNode.appendChild(node);
	}
}

function GetNodeAttribute(xmlDoc, nodeName, attributeName)
{
	if ((nodeName != "") && (attributeName != ""))
	{
		nodes = xmlDoc.getElementsByTagName(nodeName);
		if (nodes.length > 0)
			return nodes.item(0).getAttribute(attributeName);
	}
	return null;
}

function GetNodeValue(xmlRoot, nodeName)
{
    if (nodeName != "") 
    {
        nodes = xmlRoot.getElementsByTagName(nodeName)
        if (nodes.length > 0 && nodes[0].childNodes.length > 0)
            return nodes[0].childNodes[0].nodeValue;
    }
    return "";
}

function XMLDocumentToString(xmlDoc)
{
	if(typeof XMLSerializer != 'undefined')
	{
		return new XMLSerializer().serializeToString(xmlDoc);
	}
	else if(typeof xmlDoc.xml != 'undefined')
	{
		return xmlDoc.xml;
	}
	else if(typeof printNode != 'undefined')
	{
		return printNode(xmlDoc);
	}
	else if(typeof Packages != 'undefined')
	{
		try
		{
			var stringWriter = new java.io.StringWriter();
			Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(xmlDoc, stringWriter);
			return stringWriter.toString();
		}
		catch(e)
		{
			// might want to handle problem here
			return '';
		}
	}
	else
	{
		// might want to handle problem here
		return '';
	}
}

function MLX_XML_ConvertPredefinedEntitiesToName(text)
{
    text = text.replace(/&/g, "&amp;");
    text = text.replace(/"/g, "&quot;");
    text = text.replace(/'/g, "&apos;");
    text = text.replace(/</g, "&lt;");
    text = text.replace(/>/g, "&gt;");
    return text;
}