ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilXMLResultSetParser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /******************************************************************************
6  * This file is part of ILIAS, a powerful learning management system.
7  * ILIAS is licensed with the GPL-3.0, you should have received a copy
8  * of said license along with the source code.
9  * If this is not the case or you just want to try ILIAS, you'll find
10  * us at:
11  * https://www.ilias.de
12  * https://github.com/ILIAS-eLearning
13  *****************************************************************************/
15 {
16  private ?ilXMLResultSet $xmlResultSet = null;
17  private ?ilXMLResultSetRow $currentRow = null;
18  private int $currentColumnIndex = 0;
19  private string $cdata = '';
20 
21  public function __construct(string $a_xml_data = '')
22  {
24  $this->setXMLContent($a_xml_data);
25  }
26 
27  public function getXMLResultSet(): ?ilXMLResultSet
28  {
29  return $this->xmlResultSet;
30  }
31 
35  public function setHandlers($a_xml_parser): void
36  {
37  xml_set_object($a_xml_parser, $this);
38  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
39  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
40  }
41 
48  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
49  {
50  switch ($a_name) {
51  case 'result':
52  $this->xmlResultSet = new ilXMLResultSet();
53  break;
54 
55  case 'colspecs':
56  break;
57 
58  case 'colspec':
59  $this->xmlResultSet->addColumn($a_attribs["name"]);
60  break;
61  case 'row':
62  $this->currentRow = new ilXMLResultSetRow();
63  $this->xmlResultSet->addRow($this->currentRow);
64  $this->currentColumnIndex = 0;
65  break;
66  }
67  }
68 
75  public function handlerEndTag($a_xml_parser, string $a_name): void
76  {
77  switch ($a_name) {
78  case 'column':
79  $this->currentRow->setValue($this->currentColumnIndex, $this->cdata);
80  $this->currentColumnIndex++;
81  break;
82  }
83  $this->cdata = '';
84  }
85 
92  public function handlerCharacterData($a_xml_parser, string $a_data): void
93  {
94  if ($a_data !== "\n") {
95  // Replace multiple tabs with one space
96  $a_data = preg_replace("/\t+/", " ", $a_data);
97  $this->cdata .= trim($a_data);
98  }
99  }
100 }
__construct(string $a_xml_data='')
Row Class for XMLResultSet.
handlerEndTag($a_xml_parser, string $a_name)
Handler for end of element.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handlerCharacterData($a_xml_parser, string $a_data)
Handler for character data.
__construct(Container $dic, ilPlugin $plugin)
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
setXMLContent(string $a_xml_content)