How to get XML string in javascript?

Here is the function:

function getXmlString(xmlDoc) {
try {
return ((new XMLSerializer()).serializeToString(xmlDoc));
}
catch (e) {
try {
// Internet Explorer.
return (xmlDoc.xml);
}
catch (e) {
//Strange Browser ??
return (‘Xmlserializer not supported’);
}
}
}