ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilXMLResultSetParser.php
Go to the documentation of this file.
1<?php
2
19declare(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 {
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}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
__construct(string $a_xml_data='')
handlerCharacterData($a_xml_parser, string $a_data)
Handler for character data.
handlerEndTag($a_xml_parser, string $a_name)
Handler for end of element.
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
Row Class for XMLResultSet.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc