+++ /dev/null
-<?php\r
-/**\r
-* Creates XML documents.\r
-* \r
-* PHPDoc uses this helper class to generate xml documents. It's \r
-* not much what this class can do but it provides some simple\r
-* functions to handle attributes and hides file handling tasks.\r
-* \r
-* @author Ulf Wendel <ulf.wendel@phpdoc.de>\r
-* @version $Id: PhpdocXMLWriter.php,v 1.3 2000/12/03 22:37:39 uw Exp $\r
-*/\r
-class PhpdocXMLWriter extends PhpdocObject {\r
- \r
- /**\r
- * Generated XML document.\r
- *\r
- * @var string $xml\r
- */\r
- var $xml = "";\r
- \r
- /**\r
- * PHPDoc Warning object\r
- *\r
- * @var object PhpdocWarning\r
- */\r
- var $warn;\r
- \r
- /**\r
- * Filehandler used for IO operations\r
- *\r
- * @var object PhpdocFilehandler\r
- * @see PhpdocXMLWriter()\r
- */\r
- var $fileHandler;\r
- \r
- /**\r
- * Creates a new PhpdocFileHandler\r
- *\r
- * @see $filehandler\r
- */\r
- function PhpdocXMLWriter() {\r
- $this->fileHandler = new PhpdocFileHandler;\r
- } // end constructor\r
- \r
- /**\r
- * Clears the internal xml data buffer so that a new document can be passed to the object.\r
- * @access public\r
- */\r
- function free() {\r
- $this->xml = "";\r
- } // end func free\r
- \r
- /**\r
- * Adds xml to the generated xml.\r
- *\r
- * @param string xml to append\r
- * @access public\r
- */\r
- function addXML($xml) {\r
- \r
- $this->xml.= $xml;\r
- \r
- } // end func addXML\r
-\r
- /**\r
- * Saves the xml to the specified file.\r
- *\r
- * @param string Name of the target file\r
- * @access public\r
- */ \r
- function export($filename) {\r
- return $this->fileHandler->createFile($filename, $this->xml);\r
- } // end func export\r
- \r
- /**\r
- * Adds an open (or single) xml tag to the generated xml.\r
- *\r
- * Use this function to add new elements/tags to the xml document. \r
- * The tagname and all attributenames will be converted to lowercase.\r
- *\r
- * @param string elementname (tagname)\r
- * @param string value of the container: <name>value\r
- * @param array Array of attributes: $attribs[n][type] = boolean|cdata, $attribs[n][value] = value\r
- * @param boolean Flag indication that you want an empty tag like <name/>.\r
- * @access public\r
- * @see endElement()\r
- */\r
- function startElement($name, $value="", $attribs="", $close = false) {\r
- \r
- $xml = "<".strtolower($name);\r
- \r
- if (is_array($attribs)) {\r
- \r
- reset($attribs);\r
- while (list($attrib, $data)=each($attribs)) {\r
- \r
- $attrib = strtolower($attrib);\r
- $type = strtolower($data["type"]);\r
- \r
- switch($type) {\r
- case "boolean":\r
- $xml.= sprintf(' %s="%s"', $attrib, ($data["value"]) ? "true" : "false");\r
- break;\r
- \r
- case "cdata":\r
- $xml.= sprintf(' %s="%s"', $attrib, $this->xmlencode($data["value"]) );\r
- break;\r
- }\r
- }\r
- \r
- } \r
- \r
- if ($close) {\r
- \r
- $xml.= "/>";\r
- \r
- } else {\r
- \r
- $xml.= ">";\r
- if (""!=$value)\r
- $xml.= $this->xmlencode($value);\r
- \r
- }\r
- \r
- $this->xml.= $xml;\r
- \r
- } // end func startElement\r
- \r
- /**\r
- * Adds a closing xml tag to the generated xml document.\r
- *\r
- * @param string Elementname (tagname)\r
- * @access public\r
- * @see startElement()\r
- */\r
- function endElement($name) {\r
- $this->xml.= sprintf("</%s>", strtolower($name) );\r
- } // end func endElement\r
- \r
- /**\r
- * Adds a complete xml container to the generated xml document.\r
- *\r
- * @param string Elementname (tagname)\r
- * @param string Value\r
- * @param array Attributes\r
- * @access public\r
- * @see startElement(), endElement()\r
- */\r
- function addElement($name, $value="", $attribs="") {\r
- \r
- if (""==$value) {\r
- \r
- $this->startElement($name, $value, $attribs, true);\r
- \r
- } else {\r
- \r
- $this->startElement($name, $value, $attribs, false);\r
- $this->endElement($name);\r
- \r
- }\r
- \r
- } // end func addElement\r
- \r
- /**\r
- * Encodes XML values.\r
- * @param string $value\r
- * @return string $value\r
- */\r
- function xmlencode($value) {\r
-# return preg_replace( array("@<@", "@>@", "@'@", '@"@', "@&@", "@" . PHPDOC_LINEBREAK ."@", "@\n@", "@\r@"), array("<", ">", "'", """, "&", '
', '
', '
'), $value);\r
- return utf8_encode(preg_replace( array("@<@", "@>@", "@'@", '@"@', "@&@", "@" . PHPDOC_LINEBREAK . "@", "@\n@", "@\r@"), array("<", ">", "'", """, "&", '
', '
', '
'), $value));\r
- } // end func xmlencode\r
- \r
-} // end class PhpdocXMLWriter\r
-?>
\ No newline at end of file