Created
August 27, 2010 20:35
-
-
Save ehynds/554152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // the correct way to use jQuery w/ XML | |
| // also see http://gist.github.com/553364 for a normalized DOMParser | |
| var | |
| // XML string | |
| xmlString = '<wu_tang><member name="Method Man" /></wu_tang>', | |
| // DOM parsing object | |
| parser = new DOMParser(), | |
| // XML DOM object | |
| xmlObject = parser.parseFromString(xmlString , "text/xml"); | |
| // this is WRONG. It works, but you're not on an XML DOM | |
| $( xmlString ).find("member").attr("name"); // -> Method Man | |
| // the correct way | |
| $( xmlObject ).find("member").attr("name"); // -> Method Man | |
| // in XHR requests the parsing is automatically done for you by | |
| // the browser. jQuery passes it into the success callback | |
| $.ajax({ | |
| dataType: 'xml', | |
| url: 'wutang.xml', | |
| success: function( XMLObject ){ | |
| // OMG | |
| $( xmlObject ).find("member").attr("name"); // -> Method Man | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment