3 * Creates XML documents.
\r
5 * PHPDoc uses this helper class to generate xml documents. It's
\r
6 * not much what this class can do but it provides some simple
\r
7 * functions to handle attributes and hides file handling tasks.
\r
9 * @author Ulf Wendel <ulf.wendel@phpdoc.de>
\r
10 * @version $Id: PhpdocXMLWriter.php,v 1.3 2000/12/03 22:37:39 uw Exp $
\r
12 class PhpdocXMLWriter extends PhpdocObject {
\r
15 * Generated XML document.
\r
22 * PHPDoc Warning object
\r
24 * @var object PhpdocWarning
\r
29 * Filehandler used for IO operations
\r
31 * @var object PhpdocFilehandler
\r
32 * @see PhpdocXMLWriter()
\r
37 * Creates a new PhpdocFileHandler
\r
41 function PhpdocXMLWriter() {
\r
42 $this->fileHandler = new PhpdocFileHandler;
\r
43 } // end constructor
\r
46 * Clears the internal xml data buffer so that a new document can be passed to the object.
\r
54 * Adds xml to the generated xml.
\r
56 * @param string xml to append
\r
59 function addXML($xml) {
\r
63 } // end func addXML
\r
66 * Saves the xml to the specified file.
\r
68 * @param string Name of the target file
\r
71 function export($filename) {
\r
72 return $this->fileHandler->createFile($filename, $this->xml);
\r
73 } // end func export
\r
76 * Adds an open (or single) xml tag to the generated xml.
\r
78 * Use this function to add new elements/tags to the xml document.
\r
79 * The tagname and all attributenames will be converted to lowercase.
\r
81 * @param string elementname (tagname)
\r
82 * @param string value of the container: <name>value
\r
83 * @param array Array of attributes: $attribs[n][type] = boolean|cdata, $attribs[n][value] = value
\r
84 * @param boolean Flag indication that you want an empty tag like <name/>.
\r
88 function startElement($name, $value="", $attribs="", $close = false) {
\r
90 $xml = "<".strtolower($name);
\r
92 if (is_array($attribs)) {
\r
95 while (list($attrib, $data)=each($attribs)) {
\r
97 $attrib = strtolower($attrib);
\r
98 $type = strtolower($data["type"]);
\r
102 $xml.= sprintf(' %s="%s"', $attrib, ($data["value"]) ? "true" : "false");
\r
106 $xml.= sprintf(' %s="%s"', $attrib, $this->xmlencode($data["value"]) );
\r
121 $xml.= $this->xmlencode($value);
\r
127 } // end func startElement
\r
130 * Adds a closing xml tag to the generated xml document.
\r
132 * @param string Elementname (tagname)
\r
134 * @see startElement()
\r
136 function endElement($name) {
\r
137 $this->xml.= sprintf("</%s>", strtolower($name) );
\r
138 } // end func endElement
\r
141 * Adds a complete xml container to the generated xml document.
\r
143 * @param string Elementname (tagname)
\r
144 * @param string Value
\r
145 * @param array Attributes
\r
147 * @see startElement(), endElement()
\r
149 function addElement($name, $value="", $attribs="") {
\r
153 $this->startElement($name, $value, $attribs, true);
\r
157 $this->startElement($name, $value, $attribs, false);
\r
158 $this->endElement($name);
\r
162 } // end func addElement
\r
165 * Encodes XML values.
\r
166 * @param string $value
\r
167 * @return string $value
\r
169 function xmlencode($value) {
\r
170 # return preg_replace( array("@<@", "@>@", "@'@", '@"@', "@&@", "@" . PHPDOC_LINEBREAK ."@", "@\n@", "@\r@"), array("<", ">", "'", """, "&", '
', '
', '
'), $value);
\r
171 return utf8_encode(preg_replace( array("@<@", "@>@", "@'@", '@"@', "@&@", "@" . PHPDOC_LINEBREAK . "@", "@\n@", "@\r@"), array("<", ">", "'", """, "&", '
', '
', '
'), $value));
\r
172 } // end func xmlencode
\r
174 } // end class PhpdocXMLWriter
\r