function to output the html

2006-09-15
2013-04-15
  • hessodreamy

    hessodreamy - 2006-09-15

    Seems like a glaring ommission to me, so I've written a function to output the html node.

    function outputNode() {
        $nodeType=$this->iNodeType;
        $nodeName=$this->iNodeName;
        $nodeValue=$this->iNodeValue;
        $nodeAttributes=$this->iNodeAttributes;
        $output = "";
        switch($nodeType)
        {
            case NODE_TYPE_ELEMENT: $output .= "<".$nodeName." ".$nodeValue." ";
                        foreach($nodeAttributes as $attName=>$attValue) $output .= $attName."=\&quot;".$attValue."\&quot;";
                        $output .= ">";
                        break;
            case NODE_TYPE_ENDELEMENT: $output.="</$nodeName>"; break;
            case NODE_TYPE_TEXT: $output .= $nodeValue; break;
            case NODE_TYPE_COMMENT: $output .= $nodeValue; break;
            default: $output.="\n***UNDEFINED NODE***\n\ntype: $nodeType; name $nodeName; value:$nodeValue; attrib: ".print_r($nodeAttributes, true)."\n";
        }
        return $output;

    }

     
    • another_sam

      another_sam - 2009-03-29

      the same thing, 2.5 years later :P

          function iNodeToHTML()
          {
              $html = "";
             
              // element start
              if ($this->iNodeType == NODE_TYPE_ELEMENT) {
                 
                  $html = "<" . $this->iNodeName;

                  // attributes
                  $attrValues = $this->iNodeAttributes;
                  $attrNames = array_keys($attrValues);
                  $size = count($attrNames);
                  for ($i = 0; $i < $size; $i++) {
                          $name = $attrNames[$i];
                          $html .= " " . $attrNames[$i] . "=\&quot;" . $attrValues[$name] . "\&quot;";
                  }
                 
                  $html .= ">";

              // element end
              } elseif ($this->iNodeType == NODE_TYPE_ENDELEMENT) {
                  $html = "</" . $this->iNodeName . ">";

              // text or comment
              } elseif ($this->iNodeType == NODE_TYPE_TEXT ||
                        $this->iNodeType == NODE_TYPE_COMMENT) {
                           
                  $html = $this->iNodeValue;
              // fi
              }
             
              return $html;
          }

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks