Quickstart: DOM Tree building
1. Document object:
$dom = new DomDocument;
2 . Element:
$docElement = $dom->createElement(‘root’) ;
$dom->appendChild($docElement) ;
3. Set attribute:
$docElement->setAttribute(‘attrname’, ‘attrvalue’);
4. Element with textual content:
$para = $dom->createElement(‘p’, ‘Lorem ipsum dolor…’) ;
5. Append child:
$docElement->appendChild($para);
6. Import node:
$import = $dom->importNode($foreignNode, true);
If the second argument is set to true the subtree under $foreignNode will be imported, too. Now append the node named $import (see 5).
Read Full Post | Make a Comment ( None so far )