xmlDOM - XML From String jQuery Plugin

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()

Example

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() );
        });
 

Documentation

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);
});
 

你可能感兴趣的:(jquery,xml)