#?SuikaWiki/0.9 *DocumentFragment 節・ DocumentFragment 界面 (DOM) [3] [RUBYB[文書断片] [Document fragment]]は、 その名の通り[[文書]]の[[断片]]です。 [[XML]] の[[整形式]][[解析実体]]に丁度相当します。 文書[RUBY[節] [ノード]]は、要素節を1つしか持てません。 それに対して、文書断片節は複数の要素節を持てますし、 その節の外側に文節などを自由に配置できます。 [1] [RUBYB[文書断片節] [[CODE(DOM)[DocumentFragment]] node]]は、次の[[節]]を子供に持てます: :[[Element]] (要素節):[DOM1] :[[ProcessingInstruction]] (処理指令節):[DOM1] :[[Comment]] (注釈節):[DOM1] :[[Text]] (文節):[DOM1] :[[CDATASection]] (文字データ節):[DOM1] :[[EntityReference]] (実体参照節):[DOM1] [2] [CODE(DOMi)[DocumentFragment]] 界面 (Interface) は、 [CODE(DOMi)[[[Node]]]] 界面を継承します。 (DOM 1 では追加の構成員の定義はありません。) [4] 文書断片[RUBY[物体] [オブジェクト]]を [WEAK[([CODE(DOMmethod)[[[appendChild]]]] などにより)]] 他の節のどこかに挿入すると、 [WEAK[(他の節物体ならその節がそのままその位置に挿入されるのに対し、)]] 当該文書断片の''子節''がその位置に挿入されます。 その文書断片は空 (子節なし) になります。 [5] 文書の一部を用意しておいて、それを組立てるのに便利です。 例えば、次の架空の言語の DOM 束縛を使って書いた code は、見出し要素節と段落群(文書断片)節から章要素節を作ります。 [PRE[ my $heading := $document.createElement ('h'); $heading.appendChild ($document.createTextNode ('Heading')); my $paragraphs := $document.createDocumentFragment (); for my $i (1..10) { my $paragraph := $document.createElement ('p'); $paragraph.appendChild ($document.createTextNode ("Paragraph $i"); $paragraphs.appendChild ($paragraph); } ;; ここで、 $heading 節は ;; :$heading ;; +-- "Heading" ;; $paragraphs 節は ;; {断片}:$paragraphs ;; +--

;; | +-- "Paragraph 1" ;; +--

;; | +-- "Paragraph 2" ;; : ;; +--

;; +-- "Paragraph 10" ;; という構造になっている。 my $section = makeSection ($heading, $paragraphs); function makeSection ($heading, $paragraphs) { my $section = $document.createElement ('section'); $section.appendChild ($heading); $section.appendChild ($paragraph); return $section; } ;; 最終的に、 $section 節は次のような構造となる。 ;;

;; +-- :$heading ;; | +-- "Heading" ;; +--

;; | +-- "Paragraph 1" ;; +--

;; | +-- "Paragraph 2" ;; : ;; +--

;; +-- "Paragraph 10" ;; {断片} の節そのものは消滅したことに注意。 ]PRE] -[DOM1] ''Document Object Model (Core) Level 1'' -[DOM2] ''Document Object Model Core'' [[#comment]] *メモ