66 var
$genCmt =
"Generated by ILIAS XmlWriter";
75 function __construct($version =
"1.0", $outEnc =
"utf-8", $inEnc =
"utf-8")
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.
"-->";
411 $this->xmlStr .=
$data;
423 function xmlElement ($tag, $attrs = NULL,
$data = Null, $encode = TRUE, $escape = TRUE)
431 $this->
xmlStartTag($tag, $attrs, FALSE, $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 />");
475 fwrite($fp, $xmlStr);
507 $this->xmlStr .= $a_str;
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlData($data, $encode=TRUE, $escape=TRUE)
Writes data.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
static _xmlEscapeData($data)
Escapes reserved characters.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEncodeData($data)
Encodes text from input encoding into output encoding.
xmlEndTag($tag)
Writes an endtag.
__construct($version="1.0", $outEnc="utf-8", $inEnc="utf-8")
constructor
xmlFormatElement($array)
Callback function for xmlFormatData; do not invoke directly.
xmlHeader()
Writes xml header public.
xmlDumpFile($file, $format=TRUE)
Dumps xml document from memory into a file.
Create styles array
The data for the language used.
xmlSetStSheet($stSheet)
Sets stylesheet.
xmlFormatData($data)
Indents text for better reading.
appendXML($a_str)
append xml string to document
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
xmlClear()
clears xmlStr public
xmlDumpMem($format=TRUE)
Returns xml document from memory.
xmlComment($comment)
Writes a comment.
_ilXmlWriter()
destructor public