XMLHttpRequest: responseXML property - Web APIs | MDN
Value
A Document from parsing the XML or HTML received using
XMLHttpRequest, or null if no data was received or if the
data is not XML/HTML.
Exceptions
InvalidStateErrorDOMException-
Thrown if the
responseTypeisn't eitherdocumentor an empty string.
Examples
js
const xhr = new XMLHttpRequest();
xhr.open("GET", "/server");
// If specified, responseType must be empty string or "document"
xhr.responseType = "document";
// Force the response to be parsed as XML
xhr.overrideMimeType("text/xml");
xhr.onload = () => {
if (xhr.readyState === xhr.DONE && xhr.status === 200) {
console.log(xhr.response, xhr.responseXML);
}
};
xhr.send();
Specifications
| Specification |
|---|
| XMLHttpRequest # the-responsexml-attribute |
Browser compatibility
See also
XMLHttpRequestXMLHttpRequest.responseXMLHttpRequest.responseType- Parsing and serializing XML
- Parsing XML into a DOM tree:
DOMParser - Serializing a DOM tree into XML:
XMLSerializer(specifically, theserializeToString()method)