feature: Beispiele des Parsers erstellen
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user