86 var
$genCmt =
"Generated by ILIAS XmlWriter";
113 unset($this->xmlStr);
155 $length = strlen(
$data);
158 for(; $position < $length;)
160 $character = substr(
$data, $position, 1);
161 $code = Ord($character);
166 $character =
""";
170 $character =
"&";
174 $character =
"'";
188 $character = (
"&#".strval($code).
";");
193 $escapedData .= $character;
207 if ($this->inEnc == $this->outEnc)
209 $encodedData =
$data;
213 switch(strtolower($this->outEnc))
216 if(strtolower($this->inEnc) ==
"iso-8859-1")
218 $encodedData = utf8_encode(
$data);
222 die (
"<b>Error</b>: Cannot encode iso-8859-1 data in ".$this->outEnc.
223 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
228 if(strtolower($this->inEnc) ==
"utf-8")
230 $encodedData = utf8_decode(
$data);
234 die (
"<b>Error</b>: Cannot encode utf-8 data in ".$this->outEnc.
235 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
240 die (
"<b>Error</b>: Cannot encode ".$this->inEnc.
" data in ".$this->outEnc.
241 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
256 $formatedXml = preg_replace_callback(
"|<[^>]*>[^<]*|", array($this,
"xmlFormatElement"),
$data);
269 $found = trim($array[0]);
276 $tab = str_repeat(
" ", $indent * 2);
279 if (substr($found, 0, 2) ==
"</")
285 $tab = str_repeat(
" ", $indent * 2);
287 elseif (substr($found, -2, 1) ==
"/" or
288 strpos($found,
"/>") or
289 substr($found, 0, 2) ==
"<!")
293 elseif (substr($found, 0, 2) ==
"<?")
305 if (substr($found, -1) !=
">")
307 $found = str_replace(
">",
">\n".str_repeat(
" ", ($indent + 0) * 2), $found);
310 return $nl.$tab.$found;
320 $this->xmlStr .=
"<?xml version=\"".$this->version.
"\" encoding=\"".$this->outEnc.
"\"?>";
323 if ($this->dtdDef <>
"")
329 if ($this->stSheet <>
"")
335 if ($this->genCmt <>
"")
352 function xmlStartTag ($tag, $attrs = NULL, $empty = FALSE, $encode = TRUE, $escape = TRUE)
355 $this->xmlStr .=
"<".$tag;
358 if (is_array($attrs))
361 foreach ($attrs as $name => $value)
375 $this->xmlStr .=
" ".$name.
"=\"".$value.
"\"";
382 $this->xmlStr .=
"/>";
386 $this->xmlStr .=
">";
397 $this->xmlStr .=
"</".$tag.
">";
407 $this->xmlStr .=
"<!--".$comment.
"-->";
431 $this->xmlStr .=
$data;
443 function xmlElement ($tag, $attrs = NULL,
$data = Null, $encode = TRUE, $escape = TRUE)
446 if (is_string(
$data) or
450 $this->
xmlStartTag($tag, $attrs, FALSE, $encode, $escape);
461 $this->
xmlStartTag($tag, $attrs, TRUE, $encode, $escape);
474 if (!($fp = @fopen(
$file,
"w+")))
476 die (
"<b>Error</b>: Could not open \"".
$file.
"\" for writing".
477 " in <b>".__FILE__.
"</b> on line <b>".__LINE__.
"</b><br />");
526 $this->xmlStr .= $a_str;