ILIAS  release_8 Revision v8.24
class.ilXMLResultSetWriter.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
13
15 {
17 $this->xmlResultSet = $xmlResultSet;
18 }
19
20 public function start() : bool
21 {
22 $this->buildHeader();
23 $this->buildColSpecs();
24 $this->buildRows();
25 $this->buildFooter();
26 return true;
27 }
28
29 private function buildHeader() : void
30 {
31 $this->xmlSetDtdDef("<!DOCTYPE result PUBLIC \"-//ILIAS//DTD XMLResultSet//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_xml_resultset_3_7.dtd\">");
32 $this->xmlHeader();
33 $this->xmlStartTag("result");
34 }
35
36 private function buildColSpecs() : void
37 {
38 $this->xmlStartTag("colspecs");
39 foreach ($this->xmlResultSet->getColSpecs() as $colSpec) {
40 $attr = array("idx" => $colSpec->getIndex(), "name" => $colSpec->getName());
41
42 $this->xmlElement("colspec", $attr, null);
43 }
44 $this->xmlEndTag("colspecs");
45 }
46
47 private function buildRows() : void
48 {
49 $this->xmlStartTag("rows");
50 foreach ($this->xmlResultSet->getRows() as $row) {
51 $this->appendRow($row);
52 }
53 $this->xmlEndTag("rows");
54 }
55
56 private function appendRow(ilXMLResultSetRow $xmlResultSetRow) : void
57 {
58 $this->xmlStartTag('row', null);
59 foreach ($xmlResultSetRow->getColumns() as $value) {
60 $this->xmlElement('column', null, $value);
61 }
62 $this->xmlEndTag('row');
63 }
64
65 private function buildFooter() : void
66 {
67 $this->xmlEndTag('result');
68 }
69
70 public function getXML() : string
71 {
72 return $this->xmlDumpMem(false);
73 }
74}
Row Class for XMLResultSet.
XML Writer for XMLResultSet.
appendRow(ilXMLResultSetRow $xmlResultSetRow)
__construct(ilXMLResultSet $xmlResultSet)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
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.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc