Date: 2010jul22
Language: javaScript
Q. How do you parse XML with jQuery?
A. Use find() text() and attr() and .length like this:
text = '<msg><title>The Title</title><info priority="urgent"/></msg>';
doc = $.createXMLDocument(text);
// Does a <tag> exist?
title = $(doc).find('title');
if (title.length == 0) {
// No <tag>
}
// Get the text in a <tag>
title_txt = $(doc).find('title').text();
// Get an attribute
priority = $(doc).find('info').attr('priority');
.createXMLDocument is defined in:
http://plugins.jquery.com/project/createXMLDocument
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment