diff --git a/src/XMLParser.php b/src/XMLParser.php index 5c53d33..792b627 100644 --- a/src/XMLParser.php +++ b/src/XMLParser.php @@ -62,6 +62,7 @@ public function setUp(): void { // @see https://www.php.net/manual/en/function.xml-parser-set-option.php xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); + xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, true); } private function close(): void { diff --git a/tests/XMLParserCDataTest.php b/tests/XMLParserCDataTest.php new file mode 100644 index 0000000..a647b0c --- /dev/null +++ b/tests/XMLParserCDataTest.php @@ -0,0 +1,42 @@ + + + Title of Feed Item + /mylink/article1 + + + + Author Names +
Date +
Paragraph of text describing the article to be displayed

+ ]]> +
+
+XML); + } + + public function testCDataIsProperlyParsed(): void + { + $node = null; + + foreach ($this->getParser() as $item) { + if ($item instanceof XMLNodeContent && $item->tagName === 'description') { + if (trim($item->tagContent) !== '') { + $node = $item; + break; + } + } + } + + $this->assertInstanceOf(XMLNodeContent::class, $node); + $this->assertStringStartsWith("

\n ", trim($node->tagContent)); + } +} \ No newline at end of file diff --git a/tests/XMLParserWhitespacesTest.php b/tests/XMLParserWhitespacesTest.php index 17c1ba9..b5b86b4 100644 --- a/tests/XMLParserWhitespacesTest.php +++ b/tests/XMLParserWhitespacesTest.php @@ -1,6 +1,6 @@ getParser() as $item) { - if ($item instanceof \Elecena\XmlIterator\Nodes\XMLNodeContent && $item->tagName === 'loc') { + if ($item instanceof XMLNodeContent && $item->tagName === 'loc') { $locNodesContent[] = $item; } } @@ -30,4 +30,4 @@ public function testProperlyReportWhitespacesBetweenClosingTags(): void $this->assertCount(1, $locNodesContent); $this->assertEquals('https://elecena.pl/sitemap-001-search.xml.gz', $locNodesContent[0]->tagContent); } -} +} \ No newline at end of file