From 615eb561dfc43bd11ba620c9465e18ac15e22131 Mon Sep 17 00:00:00 2001 From: knut <> Date: Fri, 1 Jun 2007 05:09:32 +0000 Subject: resolved #634 and added unit tests for TXmlElement --- framework/Xml/TXmlDocument.php | 54 +++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'framework/Xml') diff --git a/framework/Xml/TXmlDocument.php b/framework/Xml/TXmlDocument.php index b4293763..0b44214e 100644 --- a/framework/Xml/TXmlDocument.php +++ b/framework/Xml/TXmlDocument.php @@ -14,7 +14,7 @@ * TXmlElement class. * * TXmlElement represents an XML element node. - * You can obtain its tagname, attributes, text between the openning and closing + * You can obtain its tag-name, attributes, text between the opening and closing * tags via the TagName, Attributes, and Value properties, respectively. * You can also retrieve its parent and child elements by Parent and Elements * properties, respectively. @@ -33,11 +33,11 @@ class TXmlElement extends TComponent */ private $_parent=null; /** - * @var string tagname of this element + * @var string tag-name of this element */ private $_tagName='unknown'; /** - * @var string text enclosed between openning and closing tags of this element + * @var string text enclosed between opening and closing tags of this element */ private $_value=''; /** @@ -51,7 +51,7 @@ class TXmlElement extends TComponent /** * Constructor. - * @param string tagname for this element + * @param string tag-name for this element */ public function __construct($tagName) { @@ -75,7 +75,7 @@ class TXmlElement extends TComponent } /** - * @return string tagname of this element + * @return string tag-name of this element */ public function getTagName() { @@ -83,7 +83,7 @@ class TXmlElement extends TComponent } /** - * @param string tagname of this element + * @param string tag-name of this element */ public function setTagName($tagName) { @@ -163,7 +163,7 @@ class TXmlElement extends TComponent } /** - * @return TXmlElement the first child element that has the specified tagname, null if not found + * @return TXmlElement the first child element that has the specified tag-name, null if not found */ public function getElementByTagName($tagName) { @@ -177,7 +177,7 @@ class TXmlElement extends TComponent } /** - * @return TList list of all child elements that have the specified tagname + * @return TList list of all child elements that have the specified tag-name */ public function getElementsByTagName($tagName) { @@ -222,6 +222,24 @@ class TXmlElement extends TComponent else return $prefix."<{$this->_tagName}$attr />"; } + + /** + * Magic-method override. Called whenever this element is used as a string. + * + * $element = new TXmlElement('tag'); + * echo $element; + * + * or + * + * $element = new TXmlElement('tag'); + * $xml = (string)$element; + * + * @return string string representation of this element + */ + public function __toString() + { + return $this->toString(); + } private function xmlEncode($str) { @@ -415,6 +433,26 @@ class TXmlDocument extends TXmlElement $encoding=empty($this->_encoding)?'':' encoding="'.$this->_encoding.'"'; return "\n".$this->toString(0); } + + /** + * Magic-method override. Called whenever this document is used as a string. + * + * $document = new TXmlDocument(); + * $document->TagName = 'root'; + * echo $document; + * + * or + * + * $document = new TXmlDocument(); + * $document->TagName = 'root'; + * $xml = (string)$document; + * + * @return string string representation of this document + */ + public function __toString() + { + return $this->saveToString(); + } /** * Recursively converts DOM XML nodes into TXmlElement -- cgit v1.2.3