From 212164beaaad87c87724672f2d1316b78016c452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Wed, 6 Dec 2023 21:00:53 +0100 Subject: [PATCH 1/3] Switch self keyword in callback to class name --- src/XMLBuild.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XMLBuild.php b/src/XMLBuild.php index dce4562..8db197e 100644 --- a/src/XMLBuild.php +++ b/src/XMLBuild.php @@ -100,7 +100,7 @@ public static function attributeValue($value) // REC-xml/#AVNormalize - preserve // REC-xml/#sec-line-ends - preserve - $buffer = preg_replace_callback('~\r\n|\r(?!\n)|\t~', array('self', 'numericEntitiesSingleByte'), $buffer); + $buffer = preg_replace_callback('~\r\n|\r(?!\n)|\t~', array('XMLBuild', 'numericEntitiesSingleByte'), $buffer); return htmlspecialchars($buffer, ENT_QUOTES, 'UTF-8', false); } From 42af9489405c704a851e0aa23ba3d249b7688a90 Mon Sep 17 00:00:00 2001 From: juniwalk Date: Sun, 27 Jul 2025 12:18:22 +0200 Subject: [PATCH 2/3] Explicit nullable type --- src/XMLReaderNode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/XMLReaderNode.php b/src/XMLReaderNode.php index 0ef42e1..6b41206 100644 --- a/src/XMLReaderNode.php +++ b/src/XMLReaderNode.php @@ -212,7 +212,7 @@ public function readOuterXml() * @throws BadMethodCallException * @return DOMNode */ - public function expand(DOMNode $baseNode = null) + public function expand(?DOMNode $baseNode = null) { if (null === $baseNode) { $baseNode = new DomDocument(); From 400763ebe9eaaa945ea32c4059f0f7ed662d1e39 Mon Sep 17 00:00:00 2001 From: juniwalk Date: Fri, 8 May 2026 15:46:12 +0200 Subject: [PATCH 3/3] Added method to get simple XML element without namespaces --- src/XMLReaderNode.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/XMLReaderNode.php b/src/XMLReaderNode.php index 6b41206..9ca4241 100644 --- a/src/XMLReaderNode.php +++ b/src/XMLReaderNode.php @@ -99,6 +99,37 @@ public function getSimpleXMLElement($className = null) return $this->simpleXML; } + /** + * Like {@see getSimpleXMLElement()} but strips all XML namespace declarations + * from the serialized node before parsing, so that plain XPath expressions + * (e.g. ./code) work on feeds that carry a default xmlns="..." attribute. + * + * @return SimpleXMLElement|null + */ + public function getSimpleXMLElementWithoutNamespaces(): ?\SimpleXMLElement + { + if ($this->reader->nodeType !== XMLReader::ELEMENT) { + return null; + } + + $doc = new \DOMDocument(); + $node = $this->expand($doc); + $xml = $doc->saveXML($node); + + if (false === $xml) { + return null; + } + + $xml = preg_replace('/\s+xmlns(?::\w+)?="[^"]*"/', '', $xml); + if (null === $xml) { + return null; + } + + $element = simplexml_load_string($xml); + + return $element instanceof \SimpleXMLElement ? $element : null; + } + /** * @deprecated since v0.1.4, use {@see getSimpleXMLElement()} instead * @return null|SimpleXMLElement