spirit posteets tagged dom  [ Profile ]

Sort by: Date / Title /

  1. 8 years ago
    1. function walkDom($node, $level = 0) {
    2.         $indent = '';
    3.         for ($i = 0; $i < $level; $i++)
    4.         $indent .= '&nbsp;&nbsp;&nbsp;&nbsp;'; //prettifying the output
    5.         if (true /*$node->nodeType == XML_TEXT_NODE*/) {
    6.                 echo $indent.'<b>'.$node->nodeName.'</b> - |'.$node->nodeValue.'|';
    7.  
    8.                 if ( $node->nodeType == XML_ELEMENT_NODE ) {
    9.                         $attributes = $node->attributes; // get all the attributes(eg: id, class)
    10.                         foreach($attributes as $attribute) {
    11.                                 echo ', '.$attribute->name.'='.$attribute->value;
    12.                         }                                                    
    13.                 }
    14.  
    15.                 echo '<br />';
    16.         }
    17.  
    18.         $cNodes = $node->childNodes;
    19.         if (count($cNodes) > 0) {
    20.                 $level++ ; // go one level deeper
    21.                 foreach($cNodes as $cNode)
    22.                         walkDom($cNode, $level);
    23.                 $level = $level - 1;
    24.         }
    25. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2092"></script>
  2. 11 years ago
    1. $.create = function() {
    2.   var ret = [], a = arguments, i, e;
    3.   a = a[0].constructor == Array ? a[0] : a;
    4.   for(i=0; i<a.length; i++) {
    5.     if(a[i+1] && a[i+1].constructor == Object) { // item is element if attributes follow
    6.       e = document.createElement(a[i]);
    7.       $(e).attr(a[++i]); // apply attributes
    8.       if (a[i] == 'table') alert ('titi');
    9.       if(a[i+1] && a[i+1].constructor == Array) $(e).append($.create(a[++i])); // optional children
    10.       ret.push(e);
    11.     } else { // item is just a text node
    12.       ret.push(document.createTextNode(a[i]));
    13.     }
    14.   }
    15.  
    16.   return ret;
    17. };
    18.  
    19.  
    20. // Usage
    21. $.create(
    22.    'table', { 'class':"MyTable" }, [
    23.       'tbody', {}, [
    24.          'tr', { 'class':"MyTableRow" }, [
    25.             'td', { 'class':"MyTableCol1" }, [ "howdy" ],
    26.             'td', { 'class':"MyTableCol2" }, [
    27.                "Link:", 'a', { 'class':"MyLink", 'href':"http://www.example.com" }, ["example.com"] ] ],
    28.          'tr', { 'class':"MyTableRow2" }, [
    29.             'td', { 'class':"MyTableCol1" }, [ "howdy" ],
    30.             'td', { 'class':"MyTableCol2" }, [
    31.                "Link:", 'a', { 'class':"MyLink", 'href':"http://www.example.com" }, ["example.com"] ] ] ] ]);
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/115"></script>

First / Previous / Next / Last / Page 1 of 1 (2 posteets)