-
- function walkDom($node, $level = 0) {
- $indent = ”;
- for ($i = 0; $i < $level; $i++)
- $indent .= ‘ ’; //prettifying the output
- if (true /*$node->nodeType == XML_TEXT_NODE*/) {
- if ( $node->nodeType == XML_ELEMENT_NODE ) {
- $attributes = $node->attributes; // get all the attributes(eg: id, class)
- foreach($attributes as $attribute) {
- }
- }
- echo ‘<br />’;
- }
- $cNodes = $node->childNodes;
- $level++ ; // go one level deeper
- foreach($cNodes as $cNode)
- walkDom($cNode, $level);
- $level = $level – 1;
- }
- }
-
-
- $.create = function() {
- var ret = [], a = arguments, i, e;
- a = a[0].constructor == Array ? a[0] : a;
- for(i=0; i<a.length; i++) {
- if(a[i+1] && a[i+1].constructor == Object) { // item is element if attributes follow
- e = document.createElement(a[i]);
- $(e).attr(a[++i]); // apply attributes
- if (a[i] == ‘table’) alert (‘titi’);
- if(a[i+1] && a[i+1].constructor == Array) $(e).append($.create(a[++i])); // optional children
- ret.push(e);
- } else { // item is just a text node
- ret.push(document.createTextNode(a[i]));
- }
- }
- return ret;
- };
- // Usage
- $.create(
- ‘table’, { ‘class’:“MyTable” }, [
- ‘tbody’, {}, [
- ‘tr’, { ‘class’:“MyTableRow” }, [
- ‘td’, { ‘class’:“MyTableCol1” }, [ “howdy” ],
- ‘td’, { ‘class’:“MyTableCol2” }, [
- “Link:”, ‘a’, { ‘class’:“MyLink”, ‘href’:“http://www.example.com” }, [“example.com”] ] ],
- ‘tr’, { ‘class’:“MyTableRow2” }, [
- ‘td’, { ‘class’:“MyTableCol1” }, [ “howdy” ],
- ‘td’, { ‘class’:“MyTableCol2” }, [
- “Link:”, ‘a’, { ‘class’:“MyLink”, ‘href’:“http://www.example.com” }, [“example.com”] ] ] ] ]);
“dom” related tags
spirit’s tags
-