blob: 85d0083d22ed28fa9dbda1b2ea7e247f85a01206 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*!
* jQuery xmlDOM Plugin v1.0
* http://outwestmedia.com/jquery-plugins/xmldom/
*
* Released: 2009-04-06
* Version: 1.0
*
* Copyright (c) 2009 Jonathan Sharp, Out West Media LLC.
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*/
(function($) {
// IE DOMParser wrapper
if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
DOMParser = function() { };
DOMParser.prototype.parseFromString = function( xmlString ) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = 'false';
doc.loadXML( xmlString );
return doc;
};
}
$.xmlDOM = function(xml, onErrorFn) {
try {
var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
if ( $.isXMLDoc( xmlDoc ) ) {
var err = $('parsererror', xmlDoc);
if ( err.length == 1 ) {
throw('Error: ' + $(xmlDoc).text() );
}
} else {
throw('Unable to parse XML');
}
} catch( e ) {
var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
if ( $.isFunction( onErrorFn ) ) {
onErrorFn( msg );
} else {
$(document).trigger('xmlParseError', [ msg ]);
}
return $([]);
}
return $( xmlDoc );
};
})(jQuery);
|