Programming Tips - jQuery: parse XML

Date: 2010jul22 Language: javaScript Q. jQuery: parse XML A. Use find() text() and attr() and .length like this:
var text = '<msg><title>The Title</title><info priority="urgent"/></msg>'; var doc = $.createXMLDocument(text); // Does a <tag> exist? var title = $(doc).find('title'); if (title.length == 0) { // No <tag> } // Get the text in a <tag> var title_txt = $(doc).find('title').text(); // Get an attribute var priority = $(doc).find('info').attr('priority');
.createXMLDocument is defined in: http://plugins.jquery.com/project/createXMLDocument