Put code on to keep the scars, don't take the <! [cdata[$text]]> as a prefix, in fact it can be a label.
| The code is as follows |
Copy Code |
| <?php $dom = new DOMDocument ("1.0"); Display document in browser as plain text For readability purposes Header ("Content-type:text/plain"); Create root element $root = $dom->createelement ("toppings"); $dom->appendchild ($root); Create child element $item = $dom->createelement ("item"); $root->appendchild ($item); Create text node $text = $dom->createtextnode ("pepperoni"); $item->appendchild ($text); Create attribute Node $price = $dom->createattribute ("price"); $item->appendchild ($price); Create attribute value node $priceValue = $dom->createtextnode ("4"); $price->appendchild ($priceValue); Create CDATA section $cdata = $dom->createcdatasection ("Customer requests that pizza is sliced into square pieces"); $root->appendchild ($cdata); Create PI $pi = $dom->createprocessinginstruction ("pizza", "bake ()"); $root->appendchild ($PI); Save and display tree echo $dom->savexml (); ?> |