46 private string $genCmt =
"Generated by ILIAS XmlWriter";
92 $length = strlen(
$data);
95 for (; $position < $length;) {
96 $character = substr(
$data, $position, 1);
97 $code = Ord($character);
101 $character =
""";
105 $character =
"&";
109 $character =
"'";
122 $character = (
"&#" . $code .
";");
127 $escapedData .= $character;
138 if ($this->inEnc == $this->outEnc) {
139 $encodedData =
$data;
142 'Differing in and out-encodings are not supported.'
154 $formatedXml = preg_replace_callback(
156 [$this,
"xmlFormatElement"],
168 $found = trim($array[0]);
175 $tab = str_repeat(
" ", $indent * 2);
178 if (substr($found, 0, 2) ==
"</") {
182 $tab = str_repeat(
" ", $indent * 2);
188 strpos($found,
"/>") or
189 substr($found, 0, 2) ==
"<!") {
191 } elseif (substr($found, 0, 2) ==
"<?") {
200 if (substr($found, -1) !=
">") {
201 $found = str_replace(
203 ">\n" . str_repeat(
" ", ($indent + 0) * 2),
208 return $nl . $tab . $found;
217 $this->xmlStr .=
"<?xml version=\"" . $this->version .
"\" encoding=\"" . $this->outEnc .
"\"?>";
220 if ($this->dtdDef <>
"") {
225 if ($this->stSheet <>
"") {
230 if ($this->genCmt <>
"") {
240 ?array $attrs =
null,
246 $this->xmlStr .=
"<" . $tag;
249 if (is_array($attrs)) {
251 foreach ($attrs as $name => $value) {
252 if ($value ===
null) {
266 $this->xmlStr .=
" " . $name .
"=\"" . $value .
"\"";
272 $this->xmlStr .=
"/>";
274 $this->xmlStr .=
">";
283 $this->xmlStr .=
"</" . $tag .
">";
291 $this->xmlStr .=
"<!--" .
$comment .
"-->";
312 $this->xmlStr .=
$data;
330 $this->xmlStartTag($tag, $attrs,
false, $encode, $escape);
333 $this->xmlData(
$data, $encode, $escape);
336 $this->xmlEndTag($tag);
339 $this->xmlStartTag($tag, $attrs,
true, $encode, $escape);
346 public function xmlDumpFile(
string $file,
bool $format =
true): void
349 if (!($fp = fopen($file,
"w+"))) {
350 throw new RuntimeException(
351 "<b>Error</b>: Could not open \"" . $file .
"\" for writing" .
352 " in <b>" . __FILE__ .
"</b> on line <b>" . __LINE__ .
"</b><br />"
361 $xmlStr = $this->xmlFormatData($this->xmlStr);
363 $xmlStr = $this->xmlStr;
367 fwrite($fp, $xmlStr);
380 $xmlStr = $this->xmlFormatData($this->xmlStr);
382 $xmlStr = $this->xmlStr;
393 $this->xmlStr .= $a_str;
Base class for ILIAS Exception handling.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
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")
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlData(string $data, bool $encode=true, bool $escape=true)
Writes data.
xmlEscapeData(string $data)
Escapes reserved characters.
xmlEncodeData(string $data)
Encodes text from input encoding into output encoding.
xmlSetStSheet(string $stSheet)
Sets stylesheet.
xmlComment(string $comment)
Writes a comment.
xmlFormatElement(array $array)
Callback function for xmlFormatData; do not invoke directly.
appendXML(string $a_str)
append xml string to document
xmlFormatData(string $data)
Indents text for better reading.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlDumpFile(string $file, bool $format=true)
Dumps xml document from memory into a file.
if(!file_exists('../ilias.ini.php'))