jQuery isXMLDoc() Method

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is isXMLDoc()?

jQuery.isXMLDoc(node) (alias $.isXMLDoc) returns true when node is an XML document or a DOM node inside an XML document (added in jQuery 1.1.4).

Remember
$.isXMLDoc(node)  → true | false

$.isXMLDoc(document)       // false  (HTML page)
$.isXMLDoc(document.body)  // false  (HTML page)

xmlDoc = $.parseXML("<root/>")
$.isXMLDoc(xmlDoc)         // true
$.isXMLDoc(xmlDoc.documentElement)  // true
NeedUse
XML node?$.isXMLDoc(node)
Parse XML text$.parseXML(str)
Parse HTML fragments$.parseHTML(str)

How to Use isXMLDoc()

Pass a DOM node; branch when it belongs to an XML tree.

  1. Start with a DOM node (page node, AJAX XML node, or parsed XML).
  2. Call $.isXMLDoc(node) — true means XML context.
  3. If you only have a string, parse first with $.parseXML.
  4. Branch your logic (selectors, namespaces, feed handling) for HTML vs XML.
PieceRequired?Role
nodeYesDOM node (or document) to test
Return—Boolean — XML document / XML node?
Common partner—$.parseXML() to create XML nodes

Pseudocode

Pseudocode
function isXMLDoc(node):
    // true if node is an XMLDocument
    // or lives inside an XMLDocument
    return node belongs to XML (not HTML)

// Typical flow:
xmlDoc = $.parseXML(rssString)
if $.isXMLDoc(xmlDoc):
    title = $(xmlDoc).find("title").text()
else:
    // treat as HTML / reject

Cheat Sheet

Keep these facts handy while detecting XML nodes with jQuery.

TopicDetail
SyntaxjQuery.isXMLDoc(node) / $.isXMLDoc(node)
SincejQuery 1.1.4
TrueXMLDocument, nodes from $.parseXML()
Falsedocument, document.body on HTML pages
Create XML$.parseXML(str)
Query XML$(xmlDoc).find("tag")

Live Preview

Pick a sample node and see what $.isXMLDoc() returns.

Browser demo of $.isXMLDoc() — same idea as the examples below.

Result
$.isXMLDoc(document)
→ false

/* HTML page document */

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Official HTML Page Checks

The jQuery API samples: page document and body are not XML.

jQuery
console.log($.isXMLDoc(document));       // false
console.log($.isXMLDoc(document.body));  // false
Try It Yourself

How It Works

  1. HTML document. The page root is <html>, not an XML root.
  2. Body node. document.body lives in that same HTML document.
  3. Result. Both official samples return false.
  4. Lesson. Do not expect true for everyday page nodes.

Example 2 — XML Document from $.parseXML()

Parsed XML produces a real XMLDocument.

jQuery
var xmlDoc = $.parseXML("<root><item/></root>");

console.log($.isXMLDoc(xmlDoc));                 // true
console.log($.isXMLDoc(xmlDoc.documentElement)); // true
Try It Yourself

How It Works

  1. Parse. $.parseXML builds a native XML document.
  2. Document. The return value itself is an XML document → true.
  3. Root element. documentElement is the <root> node inside that XML tree.
  4. Pairing. This is the usual way to get a true result in demos.

Example 3 — A Child Node Inside XML

Any node from the XML tree also returns true.

jQuery
var xmlDoc = $.parseXML(
  '<rss><channel><title>Feed</title></channel></rss>'
);
var title = $(xmlDoc).find("title")[0];

console.log($.isXMLDoc(title));           // true
console.log($.isXMLDoc(document.body));   // false
Try It Yourself

How It Works

  1. Parse RSS-like XML. Build a small XML tree with a title.
  2. Find. .find("title")[0] unwraps the native node.
  3. XML child. That node belongs to the XML document → true.
  4. Contrast. The page body remains HTML → false.

Example 4 — Branch HTML vs XML Logic

Use the boolean to choose how you handle a node.

jQuery
function describe(node) {
  return $.isXMLDoc(node) ? "XML context" : "HTML context";
}

var xmlDoc = $.parseXML("<note/>");

console.log(describe(document.body));  // "HTML context"
console.log(describe(xmlDoc));         // "XML context"
Try It Yourself

How It Works

  1. Helper. describe turns the boolean into a short label.
  2. HTML path. Page body → "HTML context".
  3. XML path. Parsed document → "XML context".
  4. Plugin use. Same pattern for feed handlers vs page DOM helpers.

Edge Cases & Pitfalls

Check these before relying on $.isXMLDoc() with real feeds.

html

Page nodes are almost always false

If you pass document or elements from the current page, expect false. That matches the official API examples.

string

Strings are not nodes

Do not pass raw XML text. Parse with $.parseXML first, then test the document or a found element.

jquery

Unwrap jQuery collections

Pass a native node: $el[0] or $el.get(0). A jQuery object itself is not a DOM node.

errors

Malformed XML may still be a document

Browsers often return a document with a parsererror node. Check parse errors after parseXML before trusting results.

Browser Support

jQuery.isXMLDoc() is available since jQuery 1.1.4+ in all modern browsers with jQuery loaded. It needs a browser DOM (not Node.js without a DOM polyfill).

✓ jQuery 1.1.4+ · Stable

jQuery.isXMLDoc()

Works in Chrome, Firefox, Safari, and Edge whenever jQuery is loaded. Pair with $.parseXML() for XML trees. Browser DOM required.

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
$.isXMLDoc() jQuery 1.1.4+

Bottom line: Use $.isXMLDoc(node) in the browser with jQuery. Create XML nodes with $.parseXML; expect false for normal HTML page nodes.

Performance Notes

ApproachCostBest for
$.isXMLDoc(node)O(1)HTML vs XML branching
$.parseXML(str)O(n) in string sizeCreate XML once, then test/query
Re-parse the same stringWastefulAvoid — parse once, reuse the document

The boolean check is cheap. Parsing dominates cost — parse once, then call isXMLDoc / .find() on the same document.

Key Takeaways

  • Role: $.isXMLDoc(node) → XML document or XML node?
  • HTML page: document / body → false (official).
  • Partner: create XML with $.parseXML.
  • Pass nodes: unwrap jQuery collections with [0].

One line: use $.isXMLDoc to tell HTML page nodes from XML trees — usually after $.parseXML.

Frequently Asked Questions

jQuery.isXMLDoc(node) returns true when node is an XML document or a DOM node inside an XML document. It returns false for nodes on a normal HTML page — including document and document.body.
Normal web pages use an HTML document whose root is <html>. The official jQuery API shows both document and document.body return false. Use isXMLDoc for XML contexts — RSS, AJAX XML, or strings parsed with $.parseXML().
Yes. After $.parseXML("<root/>"), the returned XMLDocument and its child elements return true from $.isXMLDoc(). That is the usual way beginners create XML nodes in jQuery.
Both HTML and XML nodes often look like objects. isXMLDoc checks whether the node belongs to an XML document — a specialized DOM check, not a generic type string.
Pass a real DOM node (or document). Prefer validating the value first. Falsy or non-node input is not useful and may behave differently across older jQuery builds.
When the same helper must branch between HTML page nodes and XML trees — for example choosing selectors, namespaces, or how to read text from feed items.

Next: contains()

Learn how jQuery checks whether one DOM element contains another.

contains tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful