Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CoderK opened this issue Apr 17, 2014 · 1 comment
Open

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

CoderK opened this issue Apr 17, 2014 · 1 comment

Comments

@CoderK
Copy link

CoderK commented Apr 17, 2014

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;
        },
@jcbrand
Copy link

jcbrand commented Sep 17, 2014

The Strophe.js plugins repo has moved to https://github.com/strophe/strophejs-plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants