* 素片構文解析

[3] [[構文解析器][構文解析器 (Web)]]は、[DFN[[RUBYB[[[素片構文解析]]]@en[fragment parsing]]]]モードとそうでないモードがあります。
[[素片構文解析]]かどうかによって[[構文解析器]]の挙動が微妙に違うことがよくあります。

[47] [[素片構文解析]]モードかどうかは、[[構文解析器]]の[F[現在節点]]が [CODE[null]]
以外かどうかと等価です。

[48] [[文書の直列化]]も参照。

* [CODE(HTMLa)@en[innerHTML]] 属性

** XML 取得器

[35] [[XMLの直列化]]も参照。

** XML 設定器

[31] [[Chrome]] は [[XML文書]]の [CODE(DOMa)@en[[[innerHTML]]]] で設定された値の[[整形式]]性をチェックしていて、
だめなら[[例外]]を投げるようです。 [TIME[2013-01-03T05:32:00.200Z]]

* テストケース

[REFS[
- [32] [CITE[Index of /~wakaba/test/web/dom/element/inner-html]] ([TIME[2013-01-03 12:59:26 +09:00]] 版) <http://suika.fam.cx/~wakaba/test/web/dom/element/inner-html/>
]REFS]

* 歴史

[1]
[CODE(DOMa)[innerHTML]] を使った [[Bookmarklet]] の例:
[SAMP(URI example)[[[javascript]]:[CODE(DOMa)[[[document]]]].[CODE(DOMa)[[[body]]]].[CODE(DOMa)[innerHTML]]=[CODE(DOMa)[document]].[CODE(DOMa)[body]].[CODE(DOMa)[innerHTML]].split('ー').join('━━━(゜∀゜)━━━');[CODE(DOMm)[[[focus]]]]();]]
([[名無しさん]] [sage])

[2]
[CITE[<select>のinnerHTMLについて]] <http://www.parkcity.ne.jp/~chaichan/qanda/qa5944.htm>

[4]
[[Safari]] では[[注釈節点]]が無視されるそうです。
([[名無しさん]] [sage] [WEAK[2005-09-09 21:54:14 +00:00]])

[5]
[CITE[404 Blog Not Found:javascript - element.innerHTML はなぜ速く見えるか]] <http://blog.livedoor.jp/dankogai/archives/50665647.html>
([[名無しさん]] [WEAK[2006-10-21 23:03:30 +00:00]])

[6]
[CITE[DHTML JavaScript Benchmark (DOM and innerHTML)]] <http://www.gloo.ru/blogs/gloom.dhtml_javascript_benchmark._l_en.wiki.aspx>
([[名無しさん]] [WEAK[2006-10-21 23:15:18 +00:00]])

[7]
[CITE[Bug 155723 &#8211; innerHTML will need to be fixed to work with XHTML]] ([CODE[2007-02-10 14:06:04 +09:00]] 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=155723>
([[名無しさん]])

[8]
[CITE[HTML5 IRC logs: freenode / #whatwg / 20070614]] ([CODE[2007-06-15 08:53:34 +09:00]] 版) <http://krijnhoetmer.nl/irc-logs/whatwg/20070614#l-292>
([[名無しさん]] [WEAK[2007-06-14 23:58:25 +00:00]])

[9]
[[Firefox]] 2.0 ですが、
[CODE(HTMLe)@en[[[html]]]] でも [CODE(DOMa)@en[[[innerHTML]]]]
は普通の [CODE(HTMLe)@en[[[body]]]] 内の[[要素]]と同じように処理されているようです。[CODE(HTMLe)@en[[[head]]]] や [CODE(HTMLe)@en[[[body]]]]
の[[タグ]]は無視され、結果として[[文書木]]から
[CODE(HTMLe)@en[[[head]]]] や [CODE(HTMLe)@en[[[body]]]] は削除されます。

([[名無しさん]])

[10]
[CITE[innerHTML Viewer]] ([CODE[2007-10-14 18:56:35 +09:00]] 版) <http://simon.html5.org/tools/js/innerhtml-viewer>
([[名無しさん]])

[11]
[CITE@en[Serializing PIs in HTML (detailed review of Serializing HTML fragments)]] ([[Simon Pieters]] 著, [CODE[2007-08-15 21:49:17 +09:00]] 版) <http://lists.w3.org/Archives/Public/public-html/2007Aug/0512.html>
([[名無しさん]])

[12]
[CITE[IEでp要素の中にp、div要素などを挿入してからそれのinnerHTMLプロパティをセットしようとすると「未知の実行時エラーです。」が発生する - using Misuzilla.Subtech; - subtech]] ([CODE[2008-10-07 14:21:57 +09:00]] 版) <http://subtech.g.hatena.ne.jp/mayuki/20080912/1221199569>
([[名無しさん]])


[13]
[CITE[IEの &lt;pre&gt;.innerHTML で複数のスペースを入れる方法 - 葉っぱ日記]] ([TIME[2008-10-10 01:45:25 +09:00]] 版) <http://d.hatena.ne.jp/hasegawayosuke/20080925/p1>

[14] [CITE[Eric Vasilik: Code Karma]] ([TIME[2009-03-03 09:21:21 +09:00]] 版) <http://www.ericvasilik.com/2006/07/code-karma.html>

[15] >>14 [[Trident]] チームで [[IE4]] の [[MSHTML]] を実装した人による、
[CODE(DOMa)@en[[[innerHTML]]]] の[[奇癖]]の歴史的解説です。



[16] [CITE[IRC logs: freenode / #whatwg / 20101116]]
( ([TIME[2010-11-21 00:38:22 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20101116#l-247>

[17] [CITE[IRC logs: freenode / #whatwg / 20101125]]
( ([TIME[2010-12-01 00:37:08 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20101125>

[18] 
[[Nexus S]] に搭載されている [[Android]] 2.3 のブラウザでは、
[PRE(JS example code)[
  var div = document.createElement ('div');
  div.innerHTML = '<html><style>body { background-color: red }</style>';
]PRE]
... で背景色が変わる不具合があります。 [CODE(HTMLe)@en[[[html]]]] [[開始タグ]]があると、
その後の [CODE(HTMLe)@en[[[style]]]] や [CODE(HTMLe)@en[[[link]]]]
が ([[文書]]に挿入せずとも) 適用されてしまいます。 

;; [CODE(HTMLe)@en[[[script]]]] は流石に実行されませんでした。

[19] [CITE[IRC logs: freenode / #whatwg / 20110406]]
( ([TIME[2011-04-13 22:50:03 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20110406>

[20] [CITE[IRC logs: freenode / #whatwg / 20110720]]
( ([TIME[2011-07-25 23:50:53 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20110720#l-279>

[21] [CITE@en[Web Applications 1.0 r6532 Remove bits now specced in DOMPARSING spec.]]
( ([TIME[2011-09-05 02:28:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=6531&to=6532>

[22] [CITE[IRC logs: freenode / #whatwg / 20120208]]
( ([TIME[2012-02-10 23:48:46 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20120208>

[23] [CITE[IRC logs: freenode / #whatwg / 20120315]]
( ([TIME[2012-03-21 08:57:20 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20120315>

[24] [CITE[IRC logs: freenode / #whatwg / 20120403]]
( ([TIME[2012-04-13 00:14:14 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20120403>

[25] [CITE[IRC logs: freenode / #whatwg / 20120405]]
( ([TIME[2012-04-14 17:24:02 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20120405#l-80>

[26] [CITE[Bug 14694 – innerHTML in DocumentFragment]]
( ([TIME[2012-05-04 10:21:18 +09:00]] 版))
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=14694>

[27] [CITE@en[Web Applications 1.0 r7270     innerHTML on XML nodes shouldn't expose the fact that it's faking the start and end tags...]]
( ([TIME[2012-08-25 06:39:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=7269&to=7270>

[28] [CITE[''''''[''''''whatwg'''''']'''''' Proposal for window.DocumentType.prototype.toString]]
( ([TIME[2012-10-30 02:11:05 +09:00]] 版))
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-October/037728.html>

[29] [CITE[Import innerHTML. · 00c0d17 · whatwg/domparsing]]
( ([TIME[2013-01-02 09:16:41 +09:00]] 版))
<https://github.com/whatwg/domparsing/commit/00c0d173c1665baf0cd1cbbd796eb72e7aa6bef8>

[30] [CITE[Factor out the fragment parsing algorithm and use DOM Core concepts. · 692c305 · whatwg/domparsing]]
( ([TIME[2013-01-02 09:18:55 +09:00]] 版))
<https://github.com/whatwg/domparsing/commit/692c305825374641eefc4bc20f6035873d813ad4>

[36] [CITE@en[Bug 17924 – Setting innerHTML on an SVG element will parse into HTML elements. Since innerHTML is available on Element now, we should check if the context element is an SVG element (or MathML element) other than foreignObject (etc) and use the foreign lands insertion]]
( ([TIME[2013-02-02 12:13:38 +09:00]] 版))
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=17924>

[37] [CITE[IRC logs: freenode / #whatwg / 20130219]]
( ([TIME[2013-02-22 17:10:34 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20130219#l-331>

[38] [CITE@en[Web Applications 1.0 r7768       Parser change: Handle fragment case for non-HTML nodes. This _should_ have no effect on any other case, so please do let me know if this breaks any tests!]]
( ([TIME[2013-03-26 07:29:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=7767&to=7768>

[39] [CITE@ja[innerHTMLとDOM(createElement..)での描画速度の比較 - Enjoy*Study]]
( ([TIME[2013-09-06 03:35:40 +09:00]] 版))
<http://onozaty.hatenablog.com/entry/20051230/p1>

[40] [CITE@en[Bug 23460 – Make innerHTML/outerHTML getter non-throwing?]]
( ([TIME[2013-10-14 00:08:28 +09:00]] 版))
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=23460>

[41] [CITE[IRC logs: freenode / #whatwg / 20131009]]
( ([TIME[2013-10-14 00:01:47 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20131009>

[42] [CITE@en[404385 – Consider special-casing innerHTML set when only one textnode child before and after]]
( ([TIME[2014-01-18 21:45:50 +09:00]] 版))
<https://bugzilla.mozilla.org/show_bug.cgi?id=404385>

[33] [CITE@en[updated serializing/setting innerHTML · w3c/webcomponents@c3c46d8]]
([TIME[2015-09-05 11:03:19 +09:00]] 版)
<https://github.com/w3c/webcomponents/commit/c3c46d87f9764a746523ec17853b0a5eb5ed46e0>

[34] [CITE@en[18794 – ''''''[''''''Templates'''''']'''''': Setting HTMLTemplateElement.innerHTML should append fragment to content]]
([TIME[2015-09-05 11:03:30 +09:00]] 版)
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=18794>

[43] [CITE@en[Clarify that the HTML fragment serialisation algorithm does not throw · whatwg/html@4a84d09]]
([TIME[2016-02-06 12:52:44 +09:00]] 版)
<https://github.com/whatwg/html/commit/4a84d098c705d582bbef5ccad04608d2d309c293>

[44] [CITE@en[Clarify what "it" refers to in the fragment parser]]
( ([[zcorpan]]著, [TIME[2016-06-10 18:34:33 +09:00]]))
<https://github.com/whatwg/html/commit/ca745234e4fe7bc0e0505d098b0f65405baf12e5>

[45] [CITE@en[`<iframe srcdoc="<script>">` should not execute when inserted via `innerHTML`. · Issue #2300 · whatwg/html]]
([TIME[2017-01-27 22:34:21 +09:00]])
<https://github.com/whatwg/html/issues/2300>

[46] [CITE@en[122411 - (kitchensink) Mozilla does not have a kitchen sink]]
([TIME[2017-03-20 11:38:33 +09:00]])
<https://bugzilla.mozilla.org/show_bug.cgi?id=122411#c84>

[49] [CITE@en[Serialize the children of void elements as the empty string]]
([[Zirro]]著, [TIME[2018-12-20 05:52:23 +09:00]])
<https://github.com/whatwg/html/commit/d36d3eb0e2164d3bdec168f047f15b7925bd5f83>

[50] [CITE@en[Should the innerHTML of void elements include child nodes? · Issue #4220 · whatwg/html]]
([TIME[2019-06-03 11:55:53 +09:00]])
<https://github.com/whatwg/html/issues/4220>

[51] [CITE@en[Serialize the children of void elements as the empty string by Zirro · Pull Request #4238 · whatwg/html]]
([TIME[2019-06-03 11:56:14 +09:00]])
<https://github.com/whatwg/html/pull/4238>

[52] [[CEA-2014-B]]