ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilXMLResultSetParser.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /******************************************************************************
4  * This file is part of ILIAS, a powerful learning management system.
5  * ILIAS is licensed with the GPL-3.0, you should have received a copy
6  * of said license along with the source code.
7  * If this is not the case or you just want to try ILIAS, you'll find
8  * us at:
9  * https://www.ilias.de
10  * https://github.com/ILIAS-eLearning
11  *****************************************************************************/
13 {
14  private ?ilXMLResultSet $xmlResultSet = null;
15  private ?ilXMLResultSetRow $currentRow = null;
16  private int $currentColumnIndex = 0;
17  private string $cdata = '';
18 
19  public function __construct(string $a_xml_data = '')
20  {
22  $this->setXMLContent($a_xml_data);
23  }
24 
25  public function getXMLResultSet() : ?ilXMLResultSet
26  {
27  return $this->xmlResultSet;
28  }
29 
33  public function setHandlers($a_xml_parser) : void
34  {
35  xml_set_object($a_xml_parser, $this);
36  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
37  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
38  }
39 
46  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs) : void
47  {
48  switch ($a_name) {
49  case 'result':
50  $this->xmlResultSet = new ilXMLResultSet();
51  break;
52 
53  case 'colspecs':
54  break;
55 
56  case 'colspec':
57  $this->xmlResultSet->addColumn($a_attribs["name"]);
58  break;
59  case 'row':
60  $this->currentRow = new ilXMLResultSetRow();
61  $this->xmlResultSet->addRow($this->currentRow);
62  $this->currentColumnIndex = 0;
63  break;
64  }
65  }
66 
73  public function handlerEndTag($a_xml_parser, string $a_name) : void
74  {
75  switch ($a_name) {
76  case 'column':
77  $this->currentRow->setValue($this->currentColumnIndex, $this->cdata);
78  $this->currentColumnIndex++;
79  break;
80  }
81  $this->cdata = '';
82  }
83 
90  public function handlerCharacterData($a_xml_parser, string $a_data) : void
91  {
92  if ($a_data !== "\n") {
93  // Replace multiple tabs with one space
94  $a_data = preg_replace("/\t+/", " ", $a_data);
95  $this->cdata .= trim($a_data);
96  }
97  }
98 }
__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)