Skip to content

_textToXml in strophe.private.js Does Not Work on Internet Explorer #113

@CoderK

Description

@CoderK

in storphe.private.js, the code below does not work in Internet Explorer 9-10.

        _textToXml: function( text ){
            var doc = null;

            try {
                if( window.DOMParser ){
                    var parser = new DOMParser();
                    doc = parser.parseFromString( text, 'text/xml');

                } else {
                    doc = new ActiveXObject("MSXML2.DOMDocument");
                    doc.async = false;
                    doc.loadXML(text);
                }

              ...
        },

I think that parser.parseFromString seems to be throwing an exception.
I make some workaround this problem:

        _isIE : function() {
            var myNav = navigator.userAgent.toLowerCase();
            return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
        },

        _isPlainText : function(text){
            return !/<[^>]*>((.|[\n\r])*)<\/[^>]+>/.test(text);
        },
        _textToXml: function( text ){
            var doc = null;

            /* IE는 plain text를 parseFromString의 인자로 전달하면 exception 발생함. */
            if( this._isIE() && this._isPlainText() ){
                return null;
            }

            try {
                if( window.DOMParser ){
                    var parser = new DOMParser();
                    doc = parser.parseFromString( text, 'text/xml');

                } else {
                    doc = new ActiveXObject("MSXML2.DOMDocument");
                    doc.async = false;
                    doc.loadXML(text);

                }

            } catch(e) {
                throw {
                    type: 'Parse error',
                    message: "No DOM parser object found."
                };
            }

            var error = doc.getElementsByTagName("parsererror");

            if( error.length > 0 ){
                return null;
            }

            if(doc.body == null){
                return null;
            }

            var node = document.importNode( doc.documentElement, true );
            return node;
        },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions