ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilXMLResultSetWriter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
13 {
15 
16  public function __construct(ilXMLResultSet $xmlResultSet)
17  {
19  $this->xmlResultSet = $xmlResultSet;
20  }
21 
22  public function start(): bool
23  {
24  $this->buildHeader();
25  $this->buildColSpecs();
26  $this->buildRows();
27  $this->buildFooter();
28  return true;
29  }
30 
31  private function buildHeader(): void
32  {
33  $this->xmlSetDtdDef("<!DOCTYPE result PUBLIC \"-//ILIAS//DTD XMLResultSet//EN\" \"" . ILIAS_HTTP_PATH . "/components/ILIAS/Export/xml/ilias_xml_resultset_3_7.dtd\">");
34  $this->xmlHeader();
35  $this->xmlStartTag("result");
36  }
37 
38  private function buildColSpecs(): void
39  {
40  $this->xmlStartTag("colspecs");
41  foreach ($this->xmlResultSet->getColSpecs() as $colSpec) {
42  $attr = array("idx" => $colSpec->getIndex(), "name" => $colSpec->getName());
43 
44  $this->xmlElement("colspec", $attr, null);
45  }
46  $this->xmlEndTag("colspecs");
47  }
48 
49  private function buildRows(): void
50  {
51  $this->xmlStartTag("rows");
52  foreach ($this->xmlResultSet->getRows() as $row) {
53  $this->appendRow($row);
54  }
55  $this->xmlEndTag("rows");
56  }
57 
58  private function appendRow(ilXMLResultSetRow $xmlResultSetRow): void
59  {
60  $this->xmlStartTag('row', null);
61  foreach ($xmlResultSetRow->getColumns() as $value) {
62  $this->xmlElement('column', null, $value);
63  }
64  $this->xmlEndTag('row');
65  }
66 
67  private function buildFooter(): void
68  {
69  $this->xmlEndTag('result');
70  }
71 
72  public function getXML(): string
73  {
74  return $this->xmlDumpMem(false);
75  }
76 }
XML Writer for XMLResultSet.
Row Class for XMLResultSet.
__construct(ilXMLResultSet $xmlResultSet)
xmlEndTag(string $tag)
Writes an endtag.
appendRow(ilXMLResultSetRow $xmlResultSetRow)
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlHeader()
Writes xml header.
__construct(Container $dic, ilPlugin $plugin)
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)
xmlDumpMem(bool $format=true)
Returns xml document from memory.