| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/DOMParser | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The DOMParser interface provides the ability to parse XML or HTML source code from a string into a DOM Document.
You can perform the opposite operationconverting a DOM tree into XML or HTML sourceusing the XMLSerializer interface.
In the case of an HTML document, you can also replace portions of the DOM with new DOM trees built from HTML by setting the value of the Element.innerHTML and outerHTML properties. These properties can also be read to fetch HTML fragments corresponding to the corresponding DOM subtree.
Note that XMLHttpRequest can parse XML and HTML directly from a URL-addressable resource, returning a Document in its response property.
Note:
Be aware that block-level elements like <p> will be automatically closed if another block-level element is nested inside and therefore parsed before the closing </p> tag.
DOMParser()Creates a new DOMParser object.
DOMParser.parseFromString()Parses an input TrustedHTML instance or string as HTML or XML and returns a Document.
The documentation for DOMParser.parseFromString(), this interface's only method, contains examples for parsing XML, SVG, and HTML strings.
| Specification |
|---|
| HTML # dom-parsing-and-serialization |
XMLHttpRequestXMLSerializerJSON.parse() - counterpart for JSON documents.This page was last modified on Oct 13, 2025 by MDN contributors.
DOMParserAbortControllerAbortSignalAbstractRangeAttrCDATASectionCharacterDataCommentCustomEventDOMErrorDOMExceptionDOMImplementationDOMTokenListDocumentDocumentFragmentDocumentTypeElementEventEventTargetHTMLCollectionMutationObserverMutationRecordNamedNodeMapNodeNodeIteratorNodeListProcessingInstructionQuotaExceededErrorRangeShadowRootStaticRangeTextTreeWalkerXMLDocumentXPathEvaluatorXPathExpressionXPathResultXSLTProcessorYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |