Converting XML to DOM - J Query

Problem
You need to convert a string of XML to a DOM object for use with jQuery.

Solution

Discussion
A frequent question appearing on the jQuery mailing list is how to convert a string of XML to its DOM representation that jQuery is able to operate on. When making an Ajax request with a response type of xml, the browser will automatically parse the returned XML text into a DOM object.
So, what would you do if you had a string of XML that you needed to process with jQuery? The xmlDOM plugin provides native cross-browser parsing of a string of XML and returns a jQuery-wrapped DOM object. This allows you to convert and access the XML in one step:

Another common practice is passing in the DOM object as the second argument to jQuery (the context) as follows:

This allows you to run your jQuery selection against the context object passed in; otherwise, jQuery runs the query against the document object.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

J Query Topics