Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add jquery Xml parsing functionality in older Jquery version file?

I have older version of Jquery in my application. i need ParseXML functionality to be included in it ( If i add the newwer version of jquery 1.8.2 the application is showing script error ,since lot of many other dependant plugins are written using the older version of Js file).I will be very thankfull if any one could provide me a solution for adding the ParseXML functionality in the older version of Jquery file.

like image 774
ramputan Avatar asked Dec 21 '25 02:12

ramputan


1 Answers

you can browse the source of jQuery on git hub and import the parseXML functionality 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

like image 149
Rafay Avatar answered Dec 22 '25 20:12

Rafay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!