The jQuery.parseXML() utility converts a well-formed XML string into an XMLDocument you can traverse with jQuery. This tutorial covers the official RSS demo, reading and updating nodes with .find() and .text(), comparisons with DOMParser, and pairing with jQuery.isXMLDoc().
01
Syntax
$.parseXML(s)
02
XMLDocument
Native return
03
$(doc)
jQuery wrap
04
.find()
Query nodes
05
RSS/Atom
Feed parsing
06
isXMLDoc
Detect XML
Fundamentals
Introduction
Not all server responses are JSON or HTML. RSS feeds, Atom documents, SOAP envelopes, and configuration files often arrive as XML text. Before you can read a <title> or <item> node, that string must become a parseable document tree.
jQuery added jQuery.parseXML() (also written $.parseXML()) in version 1.5. It delegates to the browser’s native XML parser and returns an XMLDocument. Wrap it with $() and you get the familiar jQuery traversal API on XML nodes — the pattern shown in the official jQuery documentation.
Concept
Understanding the jQuery.parseXML() Method
jQuery.parseXML(data) accepts one argument: a string containing well-formed XML. It returns an XMLDocument — the same type of object you get from DOM APIs when loading XML. The string is not inserted into your HTML page automatically; you query or mutate the document, then optionally copy results into the visible DOM.
XML syntax is stricter than HTML: tags must close properly, attribute quotes matter, and document structure follows XML rules. Once parsed, jQuery methods like .find(), .text(), and .attr() work on the wrapped document much like they do on HTML.
💡
Beginner Tip
The usual three-step pattern is: var doc = $.parseXML(str); then var $xml = $(doc); then $xml.find("title").text().
Foundation
📝 Syntax
General form of jQuery.parseXML:
jQuery
jQuery.parseXML( data )
// or
$.parseXML( data )
Parameters
data — a string containing well-formed XML to parse.
Return value
An XMLDocument object created by the browser’s native XML parser.
Official jQuery API workflow
jQuery
var xml = '<rss><channel><title>RSS Title</title></channel></rss>';
var xmlDoc = $.parseXML(xml);
var $xml = $(xmlDoc);
var $title = $xml.find("title");
console.log($title.text()); // "RSS Title"
Cheat Sheet
⚡ Quick Reference
Goal
Code
Parse XML string
$.parseXML(str)
Wrap for jQuery
var $x = $(xmlDoc)
Find a node
$x.find("title")
Read text
$x.find("title").text()
Native alternative
DOMParser().parseFromString()
Test XML context
$.isXMLDoc(node)
Compare
📋 $.parseXML vs parseHTML vs DOMParser
Three parsers for three different text formats.
parseXML
XMLDocument
Well-formed XML; RSS, SOAP
parseHTML
Node[]
HTML fragments; DOM nodes
DOMParser
native
XML or HTML mime types
isXMLDoc
boolean
Node from XML tree?
Hands-On
Examples Gallery
Example 1 follows the official jQuery API RSS demo. Use DevTools or the Try-it links to run each snippet.
📚 Getting Started
Parse XML and read node text with jQuery.
Example 1 — Official jQuery API RSS Demo
Parse an RSS snippet, wrap the document, find title, and read its text — matching the jQuery documentation.
jQuery
var xml =
'<rss version="2.0"><channel><title>RSS Title</title></channel></rss>';
var xmlDoc = $.parseXML(xml);
var $xml = $(xmlDoc);
var $title = $xml.find("title");
console.log($title.text()); // "RSS Title"
$.parseXML builds an in-memory XML tree. Wrapping with $() gives you a jQuery object rooted at the document, and .find("title") locates the title element anywhere in the tree.
📈 Practical Patterns
Mutate XML text, list feed items, native parsing, and XML detection.
Example 2 — Read and Change the Title (Official Demo Part 2)
After parsing, update the title text with .text() — exactly as the jQuery API demo demonstrates.
jQuery
var xml =
'<rss><channel><title>RSS Title</title></channel></rss>';
var $title = $($.parseXML(xml)).find("title");
console.log("Before:", $title.text());
$title.text("XML Title");
console.log("After:", $title.text());
jQuery mutates the XML DOM in memory. The official demo appends $title.text() to HTML elements on the page — here we log the change to show the updated XML node value.
Example 3 — Loop Over RSS Items
Find multiple <item> nodes and extract each title — a common feed-reader pattern.
jQuery
var xml =
'<rss><channel>' +
'<item><title>Post A</title></item>' +
'<item><title>Post B</title></item>' +
'</channel></rss>';
var $xml = $($.parseXML(xml));
var titles = [];
$xml.find("item > title").each(function () {
titles.push($(this).text());
});
console.log(titles.join(" | ")); // Post A | Post B
Once wrapped in jQuery, XML nodes support the same .find() and .each() patterns as HTML. Child selectors like item > title narrow results to direct title children of each item.
Example 4 — Native Equivalent with DOMParser
Modern browsers expose the same parsing through the native DOMParser API.
jQuery
var xml = '<root><name>CodeToFun</name></root>';
var withJquery = $($.parseXML(xml)).find("name").text();
var withNative = new DOMParser()
.parseFromString(xml, "text/xml")
.getElementsByTagName("name")[0].textContent;
console.log(withJquery); // CodeToFun
console.log(withNative); // CodeToFun
When your plugin accepts a node that might come from HTML or XML, $.isXMLDoc() tells you which document type you are dealing with — useful before applying HTML-specific assumptions.
Applications
🚀 Common Use Cases
RSS / Atom feeds — parse syndication XML from AJAX responses.
SOAP / XML APIs — read tagged fields from legacy web services.
Config documents — load XML settings files at runtime.
SVG as string — parse SVG markup before inserting into the page.
Cross-browser XML — consistent entry point in older jQuery projects.
Plugin development — branch on $.isXMLDoc() for mixed DOM input.
🧠 How jQuery.parseXML() Builds a Document
1
Receive XML string
Input must be well-formed XML text from a feed, API, or file.
Input
2
Native parse
Browser XML parser creates an XMLDocument tree.
Parse
3
Wrap with jQuery
$(xmlDoc) enables .find(), .text(), and traversal.
Query
4
📄
Use or display
Read values, mutate nodes, or copy text into your HTML UI.
Important
📝 Notes
Available since jQuery 1.5; still supported in jQuery 3.x.
Requires well-formed XML — HTML-style loose markup will fail or produce parser errors.
Malformed XML may yield a document with a parsererror node instead of throwing.
Namespaces affect selector behavior — RSS without prefixes usually works with simple tag names.
Pair with jQuery.isXMLDoc() when code handles both HTML and XML nodes.
For JSON APIs, use JSON.parse() — not parseXML.
Compatibility
Browser Support
jQuery.parseXML() has been part of jQuery since 1.5+. It relies on native XML parsing and works wherever jQuery and DOMParser / XMLDocument are available.
✓ jQuery 1.5+
jQuery jQuery.parseXML()
Supported in jQuery 1.x, 2.x, and 3.x across modern browsers. Native DOMParser.parseFromString(xml, "text/xml") is available in all current runtimes.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
jQuery.parseXML()Universal
Bottom line: Safe in any jQuery project that consumes XML text. Validate external feeds and handle parsererror nodes when XML comes from untrusted sources.
Wrap Up
Conclusion
The jQuery.parseXML() utility turns XML strings into XMLDocument objects you can traverse with jQuery. The official RSS demo shows the core pattern: parse, wrap, find, read, and optionally mutate — then display results in your HTML page.
For new code without jQuery, DOMParser covers the same ground. When maintaining jQuery projects that consume RSS, SOAP, or XML config files, $.parseXML remains the familiar entry point.
jQuery.parseXML(data) takes a well-formed XML string and returns an XMLDocument — the browser's native XML document object. You can wrap that document with jQuery — $(xmlDoc) — and use .find(), .text(), and other traversal methods on XML nodes.
The jQuery API parses an RSS snippet, wraps the XMLDocument with $(), finds the title element, reads its text as "RSS Title", changes it to "XML Title" with .text(), and appends the result to DOM elements — showing parse, query, and mutate in one flow.
parseHTML returns an array of HTML DOM nodes for HTML fragments. parseXML returns a full XMLDocument for well-formed XML. XML has stricter syntax rules (single root, closed tags, case-sensitive names) and is common for RSS, Atom, SVG-as-string, and SOAP responses.
Both use native browser XML parsing. jQuery.parseXML() is a thin cross-browser wrapper (since jQuery 1.5) that returns an XMLDocument. Modern code can use new DOMParser().parseFromString(str, "text/xml") directly — parseXML remains useful in legacy jQuery codebases.
The browser parser may return an XMLDocument containing a parsererror node instead of throwing. Always check for parse errors or validate structure before relying on .find() results — especially with external feeds or API responses.
After parsing, nodes from the XMLDocument belong to an XML document context. jQuery.isXMLDoc() returns true for nodes in XML documents (and false for normal HTML page nodes). Use isXMLDoc when branching logic between HTML and XML DOM trees.
Did you know?
The official jQuery parseXML demo changes the RSS title from “RSS Title” to “XML Title” using $title.text("XML Title") — proving that jQuery mutates the in-memory XML tree before you copy values into HTML. The parsed document never replaces your page; only the data you extract from it appears in the UI.