How do I add jquery Xml parsing functionality to an older jQuery version file?

I have an old version of JQuery in my application. I need ParseXML functionality to be included in it (if I add a new version of jquery 1.8.2, the application shows a script error, since many other dependent plugins are written using the old version of Js file). be very grateful if anyone can provide me with a solution to add the ParseXML function to an older version of the jQuery file.

+3


source to share


1 answer


you can view jQuery source in git hub and import functionality parseXML

like

$(document).ready(function(){
 jQuery.extend({
     parseXML: function(data) {
        var xml, tmp;
    if ( !data || typeof data !== "string" ) {
        return null;
        }
    try {
    tmp = new DOMParser();
    xml = tmp.parseFromString( data , "text/xml" );
    } catch ( e ) {
    xml = undefined;
    }
    if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
    jQuery.error( "Invalid XML: " + data );
    }
    return xml;  
    }
 })

var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "title" );
console.log($title.text());
});

      



DEMO

+2


source







All Articles