Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

DOMParser

BaselineWidely available

TheDOMParser interface providesthe ability to parseXML orHTML source code from astring into a DOMDocument.

You can perform the opposite operation—converting a DOM tree into XML or HTMLsource—using theXMLSerializer interface.

In the case of an HTML document, you can also replace portions of the DOM with new DOMtrees built from HTML by setting the value of theElement.innerHTML andouterHTML properties. These properties can also beread to fetch HTML fragments corresponding to the corresponding DOM subtree.

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

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

Constructor

DOMParser()

Creates a newDOMParser object.

Instance methods

DOMParser.parseFromString()

Parses a string using either the HTML parser or the XML parser, returning anHTMLDocument orXMLDocument.

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