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."=\"".$attValue."\""; $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;
}
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] . "=\"" . $attrValues[$name] . "\""; } $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.
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."=\"".$attValue."\"";
$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;
}
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] . "=\"" . $attrValues[$name] . "\"";
}
$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;
}