phaser/src/dom/ParseXML.js

44 lines
769 B
JavaScript
Raw Normal View History

2017-10-12 14:09:52 +00:00
/**
* [description]
*
* @function Phaser.Dom.ParseXML
* @since 3.0.0
*
* @param {string} data - The XML source stored in a string.
*
* @return {any} [description]
*/
var ParseXML = function (data)
{
var xml = '';
try
{
if (window['DOMParser'])
{
var domparser = new DOMParser();
xml = domparser.parseFromString(data, 'text/xml');
}
else
{
xml = new ActiveXObject('Microsoft.XMLDOM');
xml.loadXML(data);
}
}
catch (e)
{
xml = null;
}
if (!xml || !xml.documentElement || xml.getElementsByTagName('parsererror').length)
{
return null;
}
else
{
return xml;
}
};
module.exports = ParseXML;