ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilXMLResultSetParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
25  private int $currentColumnIndex = 0;
26  private string $cdata = '';
27 
28  public function __construct(string $a_xml_data = '')
29  {
31  $this->setXMLContent($a_xml_data);
32  }
33 
34  public function getXMLResultSet(): ?ilXMLResultSet
35  {
36  return $this->xmlResultSet;
37  }
38 
42  public function setHandlers($a_xml_parser): void
43  {
44  xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
45  xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
46  }
47 
54  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
55  {
56  switch ($a_name) {
57  case 'result':
58  $this->xmlResultSet = new ilXMLResultSet();
59  break;
60 
61  case 'colspecs':
62  break;
63 
64  case 'colspec':
65  $this->xmlResultSet->addColumn($a_attribs["name"]);
66  break;
67  case 'row':
68  $this->currentRow = new ilXMLResultSetRow();
69  $this->xmlResultSet->addRow($this->currentRow);
70  $this->currentColumnIndex = 0;
71  break;
72  }
73  }
74 
81  public function handlerEndTag($a_xml_parser, string $a_name): void
82  {
83  switch ($a_name) {
84  case 'column':
85  $this->currentRow->setValue($this->currentColumnIndex, $this->cdata);
86  $this->currentColumnIndex++;
87  break;
88  }
89  $this->cdata = '';
90  }
91 
98  public function handlerCharacterData($a_xml_parser, string $a_data): void
99  {
100  if ($a_data !== "\n") {
101  // Replace multiple tabs with one space
102  $a_data = preg_replace("/\t+/", " ", $a_data);
103  $this->cdata .= trim($a_data);
104  }
105  }
106 }
__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...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)