From ef1bb658f57cae0e4a5686f3142027c8e306b7cc Mon Sep 17 00:00:00 2001 From: Daniel Marschall <28412477+danielmarschall@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:47:55 +0200 Subject: [PATCH] Update ZugferdProfileResolver.php Fixes #133 The new version of php_zugferd makes use of libxml_get_last_error() in order to verify that SimpleXMLElement() works. However, if the user code (the code that calls php_zugferd) had accidentally raised an libxml error, then the error status will be preserved until php_zugferd calls libxml_get_last_error(). In other words: The user code had an error, completely unrelated to ZUGFeRD, and ZUGFeRD raises an error telling that the XML is wrong, which is not true. This PR fixes the issue by making sure that the libxml error storage is clean before checking the SimpleXML result. --- src/ZugferdProfileResolver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ZugferdProfileResolver.php b/src/ZugferdProfileResolver.php index 24364d6c..26789aff 100644 --- a/src/ZugferdProfileResolver.php +++ b/src/ZugferdProfileResolver.php @@ -38,6 +38,7 @@ public static function resolve(string $xmlContent): array $prevUseInternalErrors = \libxml_use_internal_errors(true); try { + libxml_clear_errors(); $xmldocument = new SimpleXMLElement($xmlContent); $typeelement = $xmldocument->xpath('/rsm:CrossIndustryInvoice/rsm:ExchangedDocumentContext/ram:GuidelineSpecifiedDocumentContextParameter/ram:ID'); if (libxml_get_last_error()) {