| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/API/DOMParser/parseFromString | [Back] [Original] |
Get to know MDN better
parseFromString(string, mimeType)
stringmimeTypeXML HTML
text/htmltext/xmlapplication/xmlapplication/xhtml+xmlimage/svg+xmltext/html HTML HTMLDocument <script> <noscript>
(text/xml, application/xml, application/xhtml+xml, image/svg+xml) XML XMLDocument
HTMLDocument XMLDocument mimeType
MIME text/html HTML MIME XML MIME application/xml image/svg+xml SVG 2
const parser = new DOMParser();
const xmlString = "<warning>Beware of the tiger</warning>";
const doc1 = parser.parseFromString(xmlString, "application/xml");
// XMLDocument
const svgString = '<circle cx="50" cy="50" r="50"/>';
const doc2 = parser.parseFromString(svgString, "image/svg+xml");
// XMLDocument
const htmlString = "<strong>Beware of the leopard</strong>";
const doc3 = parser.parseFromString(htmlString, "text/html");
// HTMLDocument
console.log(doc1.documentElement.textContent);
// "Beware of the tiger"
console.log(doc2.firstChild.tagName);
// "circle"
console.log(doc3.body.firstChild.textContent);
// "Beware of the leopard"
XML XML parseFromString XMLDocument <parsererror>
const parser = new DOMParser();
const xmlString = "<warning>Beware of the missing closing tag";
const doc = parser.parseFromString(xmlString, "application/xml");
const errorNode = doc.querySelector("parsererror");
if (errorNode) {
//
} else {
//
}
JavaScript
| HTML # dom-domparser-parsefromstring-dev |
| Web Proxy Viewer | New URL | Original Page |