66 var
$genCmt =
"Generated by ILIAS XmlWriter";
135 $length = strlen($data);
138 for(; $position < $length;)
140 $character = substr($data, $position, 1);
141 $code = Ord($character);
146 $character =
""";
150 $character =
"&";
154 $character =
"'";
168 $character = (
"&#".strval($code).
";");
173 $escapedData .= $character;
187 if ($this->inEnc == $this->outEnc)
189 $encodedData = $data;
193 switch(strtolower($this->outEnc))
196 if(strtolower($this->inEnc) ==
"iso-8859-1")
198 $encodedData = utf8_encode($data);
202 die (
"<b>Error</b>: Cannot encode iso-8859-1 data in ".$this->outEnc.
203 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
208 if(strtolower($this->inEnc) ==
"utf-8")
210 $encodedData = utf8_decode($data);
214 die (
"<b>Error</b>: Cannot encode utf-8 data in ".$this->outEnc.
215 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
220 die (
"<b>Error</b>: Cannot encode ".$this->inEnc.
" data in ".$this->outEnc.
221 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
236 $formatedXml = preg_replace_callback(
"|<[^>]*>[^<]*|", array($this,
"xmlFormatElement"), $data);
249 $found = trim($array[0]);
256 $tab = str_repeat(
" ", $indent * 2);
259 if (substr($found, 0, 2) ==
"</")
265 $tab = str_repeat(
" ", $indent * 2);
267 elseif (substr($found, -2, 1) ==
"/" or
268 strpos($found,
"/>") or
269 substr($found, 0, 2) ==
"<!")
273 elseif (substr($found, 0, 2) ==
"<?")
285 if (substr($found, -1) !=
">")
287 $found = str_replace(
">",
">\n".str_repeat(
" ", ($indent + 0) * 2), $found);
290 return $nl.$tab.$found;
300 $this->xmlStr .=
"<?xml version=\"".$this->version.
"\" encoding=\"".$this->outEnc.
"\"?>";
303 if ($this->dtdDef <>
"")
309 if ($this->stSheet <>
"")
315 if ($this->genCmt <>
"")
332 function xmlStartTag ($tag, $attrs = NULL, $empty = FALSE, $encode = TRUE, $escape = TRUE)
335 $this->xmlStr .=
"<".$tag;
338 if (is_array($attrs))
341 foreach ($attrs as $name => $value)
355 $this->xmlStr .=
" ".$name.
"=\"".$value.
"\"";
362 $this->xmlStr .=
"/>";
366 $this->xmlStr .=
">";
377 $this->xmlStr .=
"</".$tag.
">";
387 $this->xmlStr .=
"<!--".$comment.
"-->";
397 function xmlData ($data, $encode = TRUE, $escape = TRUE)
411 $this->xmlStr .= $data;
423 function xmlElement ($tag, $attrs = NULL, $data = Null, $encode = TRUE, $escape = TRUE)
426 if (is_string($data) or
431 $this->
xmlStartTag($tag, $attrs, FALSE, $encode, $escape);
434 $this->
xmlData($data, $encode, $escape);
442 $this->
xmlStartTag($tag, $attrs, TRUE, $encode, $escape);
455 if (!($fp = @fopen(
$file,
"w+")))
457 die (
"<b>Error</b>: Could not open \"".
$file.
"\" for writing".
458 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
507 $this->xmlStr .= $a_str;