<?php
 require_once(MINIXML_CLASSDIR . "/treecomp.inc.php"); class MiniXMLNode extends MiniXMLTreeComponent { var $xtext; var $xnumeric; var $xisnode; function MiniXMLNode ($value=NULL, $escapeEntities=NULL) { $this->MiniXMLTreeComponent(); $this->xtext = NULL; $this->xnumeric = NULL; $this->isnode = 1; if (! is_null($value)) { if (is_numeric($value)) { if (MINIXML_DEBUG > 0) { _MiniXMLLog("Setting numeric value of node to '$value'"); } $this->xnumeric = $value; } else { if (MINIXML_IGNOREWHITESPACES > 0) { $value = trim($value); $value = rtrim($value); } if ($escapeEntities || (MINIXML_AUTOESCAPE_ENTITIES > 0)) { $value = htmlentities($value); } if (MINIXML_DEBUG > 0) { _MiniXMLLog("Setting text value of node to '$value'"); } $this->xtext = $value; } } } function getValue () { $retStr = NULL; if (! is_null($this->xtext) ) { $retStr = $this->xtext; } elseif (! is_null($this->xnumeric)) { $retStr = "$this->xnumeric"; } if (MINIXML_DEBUG > 0) { _MiniXMLLog("MiniXMLNode::getValue returning '$retStr'"); } return $retStr; } function text ($setToPrimary = NULL, $setToAlternate=NULL) { $setTo = ($setToPrimary ? $setToPrimary : $setToAlternate); if (! is_null($setTo)) { if (! is_null($this->xnumeric) ) { return _MiniXMLError("MiniXMLNode::text() Can't set text for element with numeric set."); } elseif (! is_string($setTo) && ! is_numeric($setTo) ) { return _MiniXMLError("MiniXMLNode::text() Must pass a STRING value to set text for element ('$setTo')."); } if (MINIXML_IGNOREWHITESPACES > 0) { $setTo = trim($setTo); $setTo = rtrim($setTo); } if (MINIXML_AUTOESCAPE_ENTITIES > 0) { $setTo = htmlentities($setTo); } if (MINIXML_DEBUG > 0) { _MiniXMLLog("Setting text value of node to '$setTo'"); } $this->xtext = $setTo; } return $this->xtext; } function numeric ($setToPrim = NULL, $setToAlt = NULL) { $setTo = is_null($setToPrim) ? $setToAlt : $setToPrim; if (! is_null($setTo)) { if (! is_null($this->xtext)) { return _MiniXMLError("MiniXMLElement::numeric() Can't set numeric for element with text."); } elseif (! is_numeric($setTo)) { return _MiniXMLError("MiniXMLElement::numeric() Must pass a NUMERIC value to set numeric for element."); } if (MINIXML_DEBUG > 0) { _MiniXMLLog("Setting numeric value of node to '$setTo'"); } $this->xnumeric = $setTo; } return $this->xnumeric; } function toString ($depth=0) { if ($depth == MINIXML_NOWHITESPACES) { return $this->toStringNoWhiteSpaces(); } if (MINIXML_DEBUG > 0) { _MiniXMLLog("MiniXMLNode::toString() call with depth $depth"); } $spaces = $this->_spaceStr($depth); $retStr = $spaces; if (! is_null($this->xtext) ) { $retStr .= $this->xtext; } elseif (! is_null($this->xnumeric)) { $retStr .= $this->xnumeric; } $retStr = preg_replace("/\n\s*/sm", "\n$spaces", $retStr); return $retStr; } function toStringWithWhiteSpaces ($depth=0) { return $this->toString($depth); } function toStringNoWhiteSpaces () { if (MINIXML_DEBUG > 0) { _MiniXMLLog("MiniXMLNode::toStringNoWhiteSpaces() call with depth $depth"); } if (! is_null($this->xtext) ) { $retStr = $this->xtext; } elseif (! is_null($this->xnumeric)) { $retStr = $this->xnumeric; } return $retStr; } } ?>
