function parseXML( xml ) {
if( window.ActiveXObject && window.GetObject ) {
var dom = new ActiveXObject( 'Microsoft.XMLDOM' );
dom.loadXML( xml );
return dom;
}
if( window.DOMParser )
return new DOMParser().parseFromString( xml, 'text/xml' );
throw new Error( 'No XML parser available' );
}
var dom = parseXML('
var $dom = $(dom);
console.log( $dom.find('foo').attr('what') ); // "isit"
console.log( $dom.find('bar').text() ); // "howdy"
You could make it a plugin:
return jQuery( parseXML(xml) );
};
沒有留言:
張貼留言