feature: Beispiele des Parsers erstellen

This commit is contained in:
2022-04-27 13:37:55 +02:00
parent 0cb06e2150
commit cda93cfed7
8 changed files with 197 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace TorstenHettstedt\SaxXmlExample;
use TorstenHettstedt\XmlReader\Sax\XmlReaderInterfaces;
class TutorsReader implements XmlReaderInterfaces
{
/** @var array[] */
protected array $tutors = [];
function tag_open($tag_name, $attributes): void
{
if ($tag_name == 'COURSE') {
$this->tutors[] = [];
}
}
function cdata($tag_name, $cdata): void
{
if ($tag_name == 'NAME' || $tag_name == 'COUNTRY' || $tag_name == 'EMAIL' || $tag_name == 'PHONE') {
$this->tutors[count($this->tutors) - 1][$tag_name] = trim($cdata);
}
}
function tag_close($tag_name): void
{}
/** @return array[] */
public function getTutors(): array
{
return $this->tutors;
}
public function printTutors(): string
{
$text = '';
foreach ($this->getTutors() as $course) {
$text .= PHP_EOL;
$text .= "course Name - " . $course['NAME'] . PHP_EOL;
$text .= "Country - " . $course['COUNTRY'] . PHP_EOL;
$text .= "Email - " . $course['EMAIL'] . PHP_EOL;
$text .= "Phone - " . $course['PHONE'] . PHP_EOL;
}
return $text;
}
}