"; html += ""; html += "test</t..."> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="../../css/main.css"> <link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="../../js/vendors/jquery-3.3.1.min.js"><\/script>')</script> <script>document.write('<script src="//pagea' + 'd2.googles' + 'yndication.com/pagea' + 'd/js/a' + 'dsby' + 'google.js"><\/script>')</script> <script> var superSpecialObject = {}; superSpecialObject['google_a' + 'd_client'] = 'ca-p' + 'ub-4469282388984999'; superSpecialObject['enable_page_level_a' + 'ds'] = true; (window['a' + 'dsbygoogle'] = window['a' + 'dsbygoogle'] || []).push(superSpecialObject); </script> </head> <body> <!--[if lte IE 9]> <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p> <![endif]--> <header class="page-header js-page-header"> <a class="page-header-logo-container" href="https://geek-questions.imtqy.com/index.html"></a> <div class="page-header-text">All geek questions in one place</div> </header> <section class="page js-page"><div itemscope="" itemtype="http://schema.org/QAPage" class="page"><div class="main-col" itemprop="mainEntity" itemscope="" itemtype="http://schema.org/Question"><div class="question-header"><h1 itemprop="name"> Problems trying to parse html string using DOMParser </h1></div><div class="question"><div class="question-row"><div class="question-text"><div class="description" itemprop="text"><p> here is a snippet: </p><pre class="prettyprint-override"><code class="hljs xml">html = "<span class="hljs-meta"><!doctype html></span>"; html += "<span class="hljs-tag"><<span class="hljs-name">html</span>></span>"; html += "<span class="hljs-tag"><<span class="hljs-name">head</span>></span><span class="hljs-tag"><<span class="hljs-name">title</span>></span>test<span class="hljs-tag"></<span class="hljs-name">title</span>></span><span class="hljs-tag"></<span class="hljs-name">head</span>></span>"; html += "<span class="hljs-tag"><<span class="hljs-name">body</span>></span><span class="hljs-tag"><<span class="hljs-name">p</span>></span>test<span class="hljs-tag"></<span class="hljs-name">p</span>></span><span class="hljs-tag"></<span class="hljs-name">body</span>></span>"; html += "<span class="hljs-tag"></<span class="hljs-name">html</span>></span>"; parser = new DOMParser(); dom = parser.parseFromString (html, "text/html");</code> </pre> <p> here an error occurs when trying to execute the following lines: </p><p> <strong>Error: component return code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOMParser.parseFromString]</strong> </p><p> I am trying to figure out what is happening, but the code seems to be correct, and I searched on the Internet, I came here without any hints. </p><p> Have you encountered this error before? if so, where is the error hiding? </p></div><div class="favorite hidden"><i class="far fa-star"></i></div><div class="votes-question"><i class="glyphicon glyphicon-arrow-ups"></i><div class="vote-count greenc" itemprop="upvoteCount"> +4 </div><i class="glyphicon glyphicon-arrow-down"></i></div><div class="tags"> <a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" class="tag" title="show questions tagged with 'javascript'" rel="tag">javascript</a> <a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" class="tag" title="show questions tagged 'xml-parsing'" rel="tag">xml-parsing</a> <a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" class="tag" title="show questions tagged with 'domparser'" rel="tag">domparser</a> </div><div class="clearfix"></div><div class="action-time"> <span itemprop="author" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name"><a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" rel="noopener" target="_blank">2GN</a></span></span> <time title="2012-02-29 13:48" itemprop="dateCreated" datetime="2012-02-29T13:48:33+0000"> Feb 29 '12 at 13:48 </time></div> <a class="aa-link" href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" target="_blank" rel="noopener">source</a> <a class="s-link" href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" title="share">share</a> <div class="clearfix"></div></div></div></div><ins style="height: 90px;display: block;" data-zxname="zx-adnet" data-zxadslot="ZX-QRST" data-zxw="0" data-zxh="90" data-zxid="2" data-overlay="false"></ins><div class="answers " id="answers_hash"><div class="answers-header"> <span class="pull-left"><span itemprop="answerCount">1</span> answer</span> <div class="clearfix"></div></div><div class="answer-pager hidden"></div><div class="answer accepted last rltd" id="4362490_hash" itemscope="" itemtype="http://schema.org/Answer" itemprop="acceptedAnswer"><div class="answer-row"><div class="answer-text"><div class="desc" itemprop="text"><p> You must use the DomParser function described in <a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" src="">Accessing DOMParser JavaScript innerHTML and other properties</a> </p><p> I created a fiddle for you <a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" rel="nofollow noreferrer" src="">http://jsfiddle.net/CSAnZ/</a> </p><pre class="prettyprint-override"> <code class="hljs ruby">/* * DOMParser HTML extension * <span class="hljs-number">2012</span>-<span class="hljs-number">02</span>-<span class="hljs-number">02</span> * * By Eli Grey, <span class="hljs-symbol">http:</span>/<span class="hljs-regexp">/eligrey.com * Public domain. * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. */</span> /*! @source <span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/gist.github.com/</span><span class="hljs-number">1129031</span> *<span class="hljs-regexp">/ /</span>*global document, DOMParser*<span class="hljs-regexp">/ (function(DOMParser) { "use strict"; var DOMParser_proto = DOMParser.prototype , real_parseFromString = DOMParser_proto.parseFromString; /</span><span class="hljs-regexp">/ Firefox/</span>Opera/IE throw errors on unsupported types try { <span class="hljs-regexp">//</span> WebKit returns null on unsupported types <span class="hljs-keyword">if</span> ((new DOMParser).parseFromString(<span class="hljs-string">""</span>, <span class="hljs-string">"text/html"</span>)) { <span class="hljs-regexp">//</span> text/html parsing is natively supported <span class="hljs-keyword">return</span>; } } catch (ex) {} DOMParser_proto.parseFromString = function(markup, type) { <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/^\s*text\/html\s*(?:;|$)/i</span>.test(type)) { var doc = document.implementation.createHTMLDocument(<span class="hljs-string">""</span>) , doc_elt = doc.documentElement , first_elt; doc_elt.innerHTML = markup; first_elt = doc_elt.firstElementChild; <span class="hljs-keyword">if</span> (doc_elt.childElementCount === <span class="hljs-number">1</span> && first_elt.localName.toLowerCase() === <span class="hljs-string">"html"</span>) { doc.replaceChild(first_elt, doc_elt); } <span class="hljs-keyword">return</span> doc; } <span class="hljs-keyword">else</span> { <span class="hljs-keyword">return</span> real_parseFromString.apply(this, arguments); } }; }(DOMParser));</code> </pre></div><div class="votes-answer"><i class="glyphicon glyphicon-arrow-ups"></i><div class="vote-count greenc" itemprop="upvoteCount"> +13 </div><i class="glyphicon glyphicon-arrow-down"></i></div><div class="clearfix"></div><div class="action-time"> <span itemprop="author" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name"><a href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" rel="noopener" target="_blank">arunes</a></span></span> <time title="2012-02-29 14:18" itemprop="dateCreated" datetime="2012-02-29T14:18:22+0000"> Feb 29 '12 at 14:18 </time></div> <a class="aa-link" href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" target="_blank" rel="noopener">source</a> <a itemprop="url" class="s-link" href="https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=" title="share">share</a> <div class="clearfix"></div></div></div></div><ins style="height: 90px;display: block;margin-top: 15px;" data-zxname="zx-adnet" data-zxadslot="ZX-QRST" data-zxw="0" data-zxh="90" data-zxid="3" data-overlay="false"></ins><div class="answer-pager hidden"></div></div></div></div><p>Source: <a rel="nofollow" href="https://habr.com/ru/post/1399017/">https://habr.com/ru/post/1399017/</a></p> <section class="more-articles-navigation-panel js-more-articles-navigation-panel"> <h4>More articles:</h4> <nav class="list-of-articles-container js-list-of-articles-container"><ul class="list-of-pages js-list-of-pages"> <li><a href="../1399012/index.html">IN C # how to get file names starting with a prefix from a resource folder - c #</a></li> <li><a href="../1399013/index.html">How to handle a System.AccessViolationException? - .net</a></li> <li><a href="../1399014/index.html">DataContract and user set / get to set DateTime from string - c #</a></li> <li><a href="../1399015/index.html">Common practice is to combine and minimize external JS libraries and css files - javascript</a></li> <li><a href="../1399016/index.html">Python logs multiple files - python</a></li> <li><a href="../1399018/index.html">Best place to create a global object in ASP.NET MVC - asp.net</a></li> <li><a href="../1399019/index.html">Highlighting a tanning bed and Java - java</a></li> <li><a href="../1399020/index.html">Download multiple files using HttpFileCollectionBase issue with C # and MVC3 - c #</a></li> <li><a href="../1399021/index.html">matlab: get all permutations for a specific logical matrix - matlab</a></li> <li><a href="../1399022/index.html">SQL query to filter by two fields in combination - tsql</a></li> </ul></nav> </section><br /> <a href="../../allArticles.html"><strong>All Articles</strong></a> <script src="../../js/main.js"></script> <!-- Yandex.Metrika counter --> <script type="text/javascript" > (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter62683636 = new Ya.Metrika({ id:62683636, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/62683636" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- Google Analytics --> <script> window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date; ga('create', 'UA-166339405-1', 'auto'); ga('send', 'pageview') </script> <script src="https://www.google-analytics.com/analytics.js" async defer></script> </section> <footer class="page-footer"> <div class="page-footer-legal-info-container page-footer-element"> <p> Geek Questions | <span class="page-footer-legal-info-year js-page-footer-legal-info-year">2019</span> </p> </div> <div class="page-footer-counters-container page-footer-element"> <a class="page-footer-counter-clustrmap" href='#' title='Visit tracker'><img src='https://clustrmaps.com/map_v2.png?cl=698e5a&w=271&t=t&d=x9KFE5t3Mv44EqtuX_BNXcB69A0sIUZAkKxnezcia0Y&co=3a3a3a&ct=ffffff'/></a> </div> </footer> </body> </html>