--- title: Adding Nodes to the DOM --- The parser allows you to add new elements to an existing document. Find below an example for that. **Remarks** - It is not possible to create nodes via `->outertext`, `->innertext`, or `->plaintext`. These properties only change the text representation of a node and will return undesired results if used incorrectly. - Use [`$html->createElement`](/api/simple_html_dom/createElement) and [`$html->createTextNode`](/api/simple_html_dom/createTextNode) to create new nodes. - Use [`$node->appendChild`](/api/simple_html_dom_node/appendChild) to add a node as child to another node. - Nodes can be combined in any order. **Example** ```php

Volumes of the World's Oceans

EOD; /***************************** code *******************************************/ $html = str_get_html($doc); $body = $html->find('body', 0); $table = $html->createElement('table'); // Header row $tr = $html->createElement('tr'); foreach ($header as $entry) { $th = $html->createElement('th', $entry); $tr->appendChild($th); } $table->appendChild($tr); // Table data foreach ($data as $row) { $tr = $html->createElement('tr'); foreach ($row as $entry) { // (optional) Add info to the volume column if (is_numeric($entry)) { $value = number_format($entry); $td = $html->createElement('td', $value); $td->setAttribute('volume', $entry); } else { $td = $html->createElement('td', $entry); } $tr->appendChild($td); } $table->appendChild($tr); } $body->appendChild($table); echo $html . PHP_EOL; /** * Output (beautified) * * * * * * *

Volumes of the World's Oceans

* * * * * * * * *
OceanVolume (km^3)
Arctic Ocean18,750,000
Atlantic Ocean310,410,900
Indian Ocean264,000,000
Pacific Ocean660,000,000
Souce China Sea9,880,000
Southern Ocean71,800,000
* * */ ```