{"id":1550,"date":"2018-02-12T17:42:16","date_gmt":"2018-02-12T16:42:16","guid":{"rendered":"http:\/\/www.matjazev.net\/blog\/?p=1550"},"modified":"2018-02-12T17:42:16","modified_gmt":"2018-02-12T16:42:16","slug":"parse-xml-documents-in-javascript","status":"publish","type":"post","link":"https:\/\/www.matjazev.net\/blog\/2018\/02\/12\/parse-xml-documents-in-javascript\/","title":{"rendered":"Parse XML documents in JavaScript!"},"content":{"rendered":"<p>The problem on webpage was simple. <strong>Read XML file and process it<\/strong>. 1,2,3 and script was written, except <strong>it wasn\u2019t working in IE<\/strong>. Ok, IE is an odd creature, but still. It wasn\u2019t working even in IE 11!<\/p>\n<p>The problem was <strong>.innerHTML<\/strong> property which (at first, I thought) was returning undefined, but then I found out that the method was undefined, <strong>it was not there!<\/strong><\/p>\n<p>JavaScript DOM object in IE didn\u2019t have .innerHTML property! WTF<\/p>\n<p>After few lost hours I found the bug!<\/p>\n<p>If you parse XML string with this code:<br \/>\n<pre>return (new window.DOMParser().parseFromString(xmlStr, &lt;strong&gt;&#039;text\/xml&#039;&lt;\/strong&gt;))<\/pre><br \/>\nyou get totally different object than this one:<br \/>\n<pre>return (new window.DOMParser().parseFromString(xmlStr, &lt;strong&gt;&#039;text\/html&#039;&lt;\/strong&gt;))<\/pre><br \/>\n<strong>If you use \u2018text\/html\u2019 instead of \u2018text\/xml\u2019 in IE everything works as expected.<\/strong> All objects (all nodes, elements \u2026) will have all the expected properties!<\/p>\n<p>As I said; few lost hours \ud83d\ude41<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hoe to parse XML files in IE<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,19],"tags":[],"_links":{"self":[{"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/posts\/1550"}],"collection":[{"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/comments?post=1550"}],"version-history":[{"count":3,"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/posts\/1550\/revisions"}],"predecessor-version":[{"id":1553,"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/posts\/1550\/revisions\/1553"}],"wp:attachment":[{"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/media?parent=1550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/categories?post=1550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matjazev.net\/blog\/wp-json\/wp\/v2\/tags?post=1550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}