Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. DOMParser

DOMParser

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheDOMParser interface provides the ability to parseXML orHTML source code from a string into a DOMDocument.

You can perform the opposite operation—converting a DOM tree into XML or HTML source—using theXMLSerializer 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 theElement.innerHTML andouterHTML properties. These properties can also be read to fetch HTML fragments corresponding to the corresponding DOM subtree.

Note thatXMLHttpRequest can parse XML and HTML directly from a URL-addressable resource, returning aDocument in itsresponse property.

Note:Be aware thatblock-level elements like<p> will be automatically closed if another block-level element is nested inside and therefore parsed before the closing</p> tag.

Constructor

DOMParser()

Creates a newDOMParser object.

Instance methods

DOMParser.parseFromString()

Parses an inputTrustedHTML instance or string as HTML or XML and returns aDocument.

Examples

The documentation forDOMParser.parseFromString(), this interface's only method, contains examples for parsing XML, SVG, and HTML strings.

Specifications

Specification
HTML
# dom-parsing-and-serialization

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp