66 public $genCmt =
"Generated by ILIAS XmlWriter";
135 $length = strlen(
$data);
138 for (; $position < $length;) {
139 $character = substr(
$data, $position, 1);
140 $code = Ord($character);
144 $character =
""";
148 $character =
"&";
152 $character =
"'";
165 $character = (
"&#" . strval(
$code) .
";");
170 $escapedData .= $character;
184 if ($this->inEnc == $this->outEnc) {
185 $encodedData =
$data;
187 switch (strtolower($this->outEnc)) {
189 if (strtolower($this->inEnc) ==
"iso-8859-1") {
190 $encodedData = utf8_encode(
$data);
192 die(
"<b>Error</b>: Cannot encode iso-8859-1 data in " . $this->outEnc .
193 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />");
198 if (strtolower($this->inEnc) ==
"utf-8") {
199 $encodedData = utf8_decode(
$data);
201 die(
"<b>Error</b>: Cannot encode utf-8 data in " . $this->outEnc .
202 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />");
207 die(
"<b>Error</b>: Cannot encode " . $this->inEnc .
" data in " . $this->outEnc .
208 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />");
223 $formatedXml = preg_replace_callback(
"|<[^>]*>[^<]*|", array($this,
"xmlFormatElement"),
$data);
236 $found = trim($array[0]);
243 $tab = str_repeat(
" ", $indent * 2);
246 if (substr($found, 0, 2) ==
"</") {
250 $tab = str_repeat(
" ", $indent * 2);
251 } elseif (substr($found, -2, 1) ==
"/" or 252 strpos($found,
"/>")
or 253 substr($found, 0, 2) ==
"<!") {
255 } elseif (substr($found, 0, 2) ==
"<?") {
264 if (substr($found, -1) !=
">") {
265 $found = str_replace(
">",
">\n" . str_repeat(
" ", ($indent + 0) * 2), $found);
268 return $nl .
$tab . $found;
278 $this->xmlStr .=
"<?xml version=\"" . $this->version .
"\" encoding=\"" . $this->outEnc .
"\"?>";
281 if ($this->dtdDef <>
"") {
286 if ($this->stSheet <>
"") {
291 if ($this->genCmt <>
"") {
307 public function xmlStartTag(
$tag, $attrs = null, $empty =
false, $encode =
true, $escape =
true)
310 $this->xmlStr .=
"<" .
$tag;
313 if (is_array($attrs)) {
315 foreach ($attrs as
$name => $value) {
326 $this->xmlStr .=
" " .
$name .
"=\"" . $value .
"\"";
332 $this->xmlStr .=
"/>";
334 $this->xmlStr .=
">";
345 $this->xmlStr .=
"</" .
$tag .
">";
355 $this->xmlStr .=
"<!--" .
$comment .
"-->";
377 $this->xmlStr .=
$data;
418 if (!($fp = @
fopen($file,
"w+"))) {
419 die(
"<b>Error</b>: Could not open \"" . $file .
"\" for writing" .
420 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />");
463 $this->xmlStr .= $a_str;
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlDumpMem($format=true)
Returns xml document from memory.
static _xmlEscapeData($data)
Escapes reserved characters.
xmlEncodeData($data)
Encodes text from input encoding into output encoding.
xmlData($data, $encode=true, $escape=true)
Writes data.
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.
xmlSetStSheet($stSheet)
Sets stylesheet.
xmlFormatData($data)
Indents text for better reading.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
appendXML($a_str)
append xml string to document
xmlClear()
clears xmlStr public
if(function_exists('posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
xmlDumpFile($file, $format=true)
Dumps xml document from memory into a file.
xmlComment($comment)
Writes a comment.
_ilXmlWriter()
destructor public