(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('xml2js'), require('@iotize/device-client.js/config/iotize-studio')) :
    typeof define === 'function' && define.amd ? define('@iotize/device-client.js/config/iotize-studio/parser/xml', ['xml2js', '@iotize/device-client.js/config/iotize-studio'], factory) :
    (global = global || self, (global.iotize = global.iotize || {}, global.iotize['device-client'] = global.iotize['device-client'] || {}, global.iotize['device-client'].js = global.iotize['device-client'].js || {}, global.iotize['device-client'].js.config = global.iotize['device-client'].js.config || {}, global.iotize['device-client'].js.config['iotize-studio'] = global.iotize['device-client'].js.config['iotize-studio'] || {}, global.iotize['device-client'].js.config['iotize-studio'].parser = global.iotize['device-client'].js.config['iotize-studio'].parser || {}, global.iotize['device-client'].js.config['iotize-studio'].parser.xml = factory(global.xml2js, global.iotize['device-client'].js.config['iotize-studio'])));
}(this, (function (xml2js, iotizeStudio) { 'use strict';

    xml2js = xml2js && xml2js.hasOwnProperty('default') ? xml2js['default'] : xml2js;
    iotizeStudio = iotizeStudio && iotizeStudio.hasOwnProperty('default') ? iotizeStudio['default'] : iotizeStudio;

    var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

    function commonjsRequire () {
    	throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
    }

    function unwrapExports (x) {
    	return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
    }

    function createCommonjsModule(fn, module) {
    	return module = { exports: {} }, fn(module, module.exports), module.exports;
    }

    function getCjsExportFromNamespace (n) {
    	return n && n['default'] || n;
    }

    var xmlParser = createCommonjsModule(function (module, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });

    /**
     * Convert XML to Javascript Object
     */
    var XMLParser = /** @class */ (function () {
        function XMLParser() {
        }
        /**
         * Parse XML input synchonously
         * @param xml
         */
        XMLParser.prototype.parseSync = function (xml) {
            var res = null;
            xml2js.parseString(xml, function (err, result) {
                if (err !== null) {
                    throw err;
                }
                res = result;
            });
            return res;
        };
        /**
         * Parse XML input async
         * @param xml
         */
        XMLParser.prototype.parse = function (xml) {
            xml = this.cleanifyXml(xml);
            return new Promise(function (resolve, reject) {
                xml2js.parseString(xml, function (err, result) {
                    if (err !== null) {
                        reject(err);
                    }
                    resolve(result);
                });
            });
        };
        /**
         * Cleanify the xml input before parsing
         * @see http://stackoverflow.com/questions/34783452/cannot-parse-xml-error-non-whitespace-before-first-tag-line-0-column-1-cha
         */
        XMLParser.prototype.cleanifyXml = function (xml) {
            if (!xml) {
                return xml;
            }
            return xml.replace('\ufeff', '').trim();
        };
        return XMLParser;
    }());
    exports.XMLParser = XMLParser;

    });

    var xmlParser$1 = unwrapExports(xmlParser);
    var xmlParser_1 = xmlParser.XMLParser;

    var configFactoryExtension = createCommonjsModule(function (module, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });


    /**
     * Create IotizeConfigModel from a XML string
     * @param xml
     */
    iotizeStudio.IotizeConfigFactory.fromXML = function (xml) {
        return new iotizeStudio.IotizeConfigModel(new xmlParser.XMLParser().parseSync(xml));
    };

    });

    var configFactoryExtension$1 = unwrapExports(configFactoryExtension);

    var public_api = createCommonjsModule(function (module, exports) {
    "use strict";
    function __export(m) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }
    Object.defineProperty(exports, "__esModule", { value: true });
    __export(xmlParser);


    });

    var public_api$1 = unwrapExports(public_api);

    var iotizeDeviceClient_jsConfigIotizeStudioParserXml = createCommonjsModule(function (module, exports) {
    "use strict";
    /**
     * Generated bundle index. Do not edit.
     */
    function __export(m) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }
    Object.defineProperty(exports, "__esModule", { value: true });
    __export(public_api);

    });

    var iotizeDeviceClient_jsConfigIotizeStudioParserXml$1 = unwrapExports(iotizeDeviceClient_jsConfigIotizeStudioParserXml);

    return iotizeDeviceClient_jsConfigIotizeStudioParserXml$1;

})));
//# sourceMappingURL=iotize-device-client.js-config-iotize-studio-parser-xml.umd.js.map
