From cda93cfed7732742d58751ae3c1c08e5ada01d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Wed, 27 Apr 2022 13:37:55 +0200 Subject: [PATCH] feature: Beispiele des Parsers erstellen --- example/.gitignore | 2 ++ example/app/reader.php | 36 ++++++++++++++++++++++++++ example/composer.json | 27 ++++++++++++++++++++ example/src/TutorsReader.php | 49 ++++++++++++++++++++++++++++++++++++ example/xml/tutors_1.xml | 23 +++++++++++++++++ example/xml/tutors_2.xml | 20 +++++++++++++++ example/xml/tutors_3.xml | 20 +++++++++++++++ example/xml/tutors_4.xml | 20 +++++++++++++++ 8 files changed, 197 insertions(+) create mode 100644 example/.gitignore create mode 100644 example/app/reader.php create mode 100644 example/composer.json create mode 100644 example/src/TutorsReader.php create mode 100644 example/xml/tutors_1.xml create mode 100644 example/xml/tutors_2.xml create mode 100644 example/xml/tutors_3.xml create mode 100644 example/xml/tutors_4.xml diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..ff72e2d --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,2 @@ +/composer.lock +/vendor diff --git a/example/app/reader.php b/example/app/reader.php new file mode 100644 index 0000000..dc93e4b --- /dev/null +++ b/example/app/reader.php @@ -0,0 +1,36 @@ +parseFile($file_path); + unset($parser); + printf(PHP_EOL . '## %s', $file_path); + echo $tutors->printTutors(); + assert($tutors->printTutors() === SHOULD_TEXT); +} diff --git a/example/composer.json b/example/composer.json new file mode 100644 index 0000000..98120c4 --- /dev/null +++ b/example/composer.json @@ -0,0 +1,27 @@ +{ + "name": "torsten-hettstedt/sax-xml-reader-example", + "description": "SAX-XML-Reader Beispiele", + "minimum-stability": "dev", + "license": "GPL-3.0-or-later", + "repositories": [ + { + "type": "path", + "url": "../" + } + ], + "authors": [ + { + "name": "Torsten L\u00fccke", + "email": "developer@torsten-hettstedt.de" + } + ], + "require": { + "php": ">=7.4", + "torsten-hettstedt/sax-xml-reader": "*" + }, + "autoload": { + "psr-4": { + "TorstenHettstedt\\SaxXmlExample\\": "src" + } + } +} \ No newline at end of file diff --git a/example/src/TutorsReader.php b/example/src/TutorsReader.php new file mode 100644 index 0000000..2527c32 --- /dev/null +++ b/example/src/TutorsReader.php @@ -0,0 +1,49 @@ +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; + } +} \ No newline at end of file diff --git a/example/xml/tutors_1.xml b/example/xml/tutors_1.xml new file mode 100644 index 0000000..2b932a7 --- /dev/null +++ b/example/xml/tutors_1.xml @@ -0,0 +1,23 @@ + + + + Android + India + contact@tutorialspoint.com + 123456789 + + + + Java + India + contact@tutorialspoint.com + 123456789 + + + + HTML + India + contact@tutorialspoint.com + 123456789 + + \ No newline at end of file diff --git a/example/xml/tutors_2.xml b/example/xml/tutors_2.xml new file mode 100644 index 0000000..299d986 --- /dev/null +++ b/example/xml/tutors_2.xml @@ -0,0 +1,20 @@ + + + + Android + India + contact@tutorialspoint.com + 123456789 + + + Java + India + contact@tutorialspoint.com + 123456789 + + + HTML + India + contact@tutorialspoint.com + 123456789 + \ No newline at end of file diff --git a/example/xml/tutors_3.xml b/example/xml/tutors_3.xml new file mode 100644 index 0000000..b7b7c96 --- /dev/null +++ b/example/xml/tutors_3.xml @@ -0,0 +1,20 @@ + + + + Android + India + contact@tutorialspoint.com + 123456789 + + + Java + India + contact@tutorialspoint.com + 123456789 + + + HTML + India + contact@tutorialspoint.com + 123456789 + \ No newline at end of file diff --git a/example/xml/tutors_4.xml b/example/xml/tutors_4.xml new file mode 100644 index 0000000..6aecec8 --- /dev/null +++ b/example/xml/tutors_4.xml @@ -0,0 +1,20 @@ + + + + Android + India + contact@tutorialspoint.com + 123456789 + + + Java + India + contact@tutorialspoint.com + 123456789 + + + HTML + India + contact@tutorialspoint.com + 123456789 +< \ No newline at end of file