Convert a String of XML to a DOM Object with jQuery

The xmlDOM jQuery plugin takes a string of XML and converts it into an XML DOM object for use with jQuery.

jQuery Plugin Methods

The xmlDOM plugin adds the following jQuery method:

  • $.xmlDOM()


Here's an example of how it works

var xml = '<item><title>Hello world!</title></item>';
$.xmlDOM( xml )
    .find('item > title')
        .each(function() {
            // Alert's 'Hello world!'
            alert( $(this).text() );
Run the example!


The xmlDOM plugin provides the $.xmlDOM(xml string, error callback) method that accepts two arguments: the string to convert and an optional callback method that is triggered if an error occurs. $.xmlDOM() will return a jQuery object containing the XML DOM. Here is an example:

var xmlString = '<item><title>Hello world!</title></item>';
var $dom = $.xmlDOM(xmlString, function(error) {
    alert('A parse error occurred! ' + error);
$dom.find('item > string');

There are two methods for capturing errors. The first is a callback provided at execution time. If a callback isn't provided then a xmlParseError event is triggered on the document object. You may capture and respond to the event as follows:

$(document).bind('xmlParseError', function(event, error) {
    alert('A parse error occurred! ' + error);


The xmlDOM jQuery Plugin is dual licensed under the MIT or GPL licenses.


xmlDOM 1.0 Released 2009-04-06

Tested against: jQuery 1.3.2, Internet Explorer 6+, Firefox 2+, Safari 3.x, Opera 9.63


For questions or feedback, contact Jonathan Sharp at Out West Media.

Custom jQuery Development

Need this plugin modified or integrated? Out West Media provides custom jQuery development services so contact Jonathan Sharp today for a free quote.