Tag Archives: JavaScirpt

JavaScript: Convert string into a XML object

Here is a small function in JavaScript, which converts a string into a XML object.

function StringToXML(text) {
    if (window.ActiveXObject) {
        var doc = new ActiveXObject('Microsoft.XMLDOM');
	doc.async = 'false';
	doc.loadXML(text);
    } else {
        var parser = new DOMParser();
	var doc = parser.parseFromString(text, 'text/xml')
    }
    return doc;
}
Advertisements
Tagged , ,