44 private string $genCmt =
"Generated by ILIAS XmlWriter";
47 string $version =
"1.0",
48 string $outEnc =
"utf-8",
49 string $inEnc =
"utf-8" 90 $length = strlen($data);
93 for (; $position < $length;) {
94 $character = substr($data, $position, 1);
95 $code = Ord($character);
99 $character =
""";
103 $character =
"&";
107 $character =
"'";
120 $character = (
"&#" . $code .
";");
125 $escapedData .= $character;
136 if ($this->inEnc == $this->outEnc) {
137 $encodedData =
$data;
139 switch (strtolower($this->outEnc)) {
141 if (strtolower($this->inEnc) ==
"iso-8859-1") {
142 $encodedData = utf8_encode($data);
145 "<b>Error</b>: Cannot encode iso-8859-1 data in " . $this->outEnc .
146 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />" 152 if (strtolower($this->inEnc) ==
"utf-8") {
153 $encodedData = utf8_decode($data);
156 "<b>Error</b>: Cannot encode utf-8 data in " . $this->outEnc .
157 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />" 164 "<b>Error</b>: Cannot encode " . $this->inEnc .
" data in " . $this->outEnc .
165 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />" 178 $formatedXml = preg_replace_callback(
180 [$this,
"xmlFormatElement"],
192 $found = trim($array[0]);
199 $tab = str_repeat(
" ", $indent * 2);
202 if (substr($found, 0, 2) ==
"</") {
206 $tab = str_repeat(
" ", $indent * 2);
212 strpos($found,
"/>") or
213 substr($found, 0, 2) ==
"<!") {
215 } elseif (substr($found, 0, 2) ==
"<?") {
224 if (substr($found, -1) !=
">") {
225 $found = str_replace(
227 ">\n" . str_repeat(
" ", ($indent + 0) * 2),
232 return $nl . $tab . $found;
241 $this->xmlStr .=
"<?xml version=\"" . $this->version .
"\" encoding=\"" . $this->outEnc .
"\"?>";
244 if ($this->dtdDef <>
"") {
249 if ($this->stSheet <>
"") {
254 if ($this->genCmt <>
"") {
264 ?array $attrs = null,
270 $this->xmlStr .=
"<" . $tag;
273 if (is_array($attrs)) {
275 foreach ($attrs as
$name => $value) {
276 if ($value === null) {
290 $this->xmlStr .=
" " .
$name .
"=\"" . $value .
"\"";
296 $this->xmlStr .=
"/>";
298 $this->xmlStr .=
">";
307 $this->xmlStr .=
"</" . $tag .
">";
315 $this->xmlStr .=
"<!--" . $comment .
"-->";
336 $this->xmlStr .=
$data;
350 if (is_string(
$data) or
354 $this->
xmlStartTag($tag, $attrs,
false, $encode, $escape);
363 $this->
xmlStartTag($tag, $attrs,
true, $encode, $escape);
373 if (!($fp = fopen($file,
"w+"))) {
375 "<b>Error</b>: Could not open \"" . $file .
"\" for writing" .
376 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />" 391 fwrite($fp, $xmlStr);
417 $this->xmlStr .= $a_str;
xmlData(string $data, bool $encode=true, bool $escape=true)
Writes data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEscapeData(string $data)
Escapes reserved characters.
xmlComment(string $comment)
Writes a comment.
xmlSetGenCmt(string $genCmt)
Sets generated comment.
appendXML(string $a_str)
append xml string to document
xmlDumpFile(string $file, bool $format=true)
Dumps xml document from memory into a file.
xmlEndTag(string $tag)
Writes an endtag.
xmlEncodeData(string $data)
Encodes text from input encoding into output encoding.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlFormatData(string $data)
Indents text for better reading.
xmlHeader()
Writes xml header.
xmlFormatElement(array $array)
Callback function for xmlFormatData; do not invoke directly.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
__construct(string $version="1.0", string $outEnc="utf-8", string $inEnc="utf-8")
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlSetStSheet(string $stSheet)
Sets stylesheet.