-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with SimpleXML processing COUNTER report namespaces. #485
Comments
This fails if a namespace is used within the Report element. The only reliable solution I found was to get all the namespace used in the document, then remove them.
This seems like a bit of a hack but I couldn't get anything else to work. |
Same error, 3.0.1 PHP Fatal error: Call to a member function attributes() on null in C:\Apache24\htdocs\coral\usage\admin\classes\domain\SushiService.php on line 630 |
Did you try my second fix? If it works for you, I'll submit a pull request to get it included in the code |
Hi, Your second fix gives me the error: [Mon Mar 18 10:33:17.887759 2019] [:error] [pid 5268:tid 960] [client 10.32.48.31:60819] PHP Notice: Trying to get property of non-object in C:\Apache24\htdocs\coral\usage\admin\classes\domain\SushiService.php on line 639, referer: https://archives.yu.edu/coral/usage/sushi.php And my line 639: $report = $xml->Body->ReportResponse->Report->Report; |
The first fix works for me. |
Which vendor were you using when you got this error? |
EBSCO. |
I just tried EBSCO BR2 and JR1 and it worked fine with the second changes. Can't remember which vendor was failing on the first set. |
EBSCO.
[cid:c978341e-ba18-48c7-ae44-d961dcb0b165]
…________________________________
From: vinny75 <notifications@github.com>
Sent: Monday, March 18, 2019 1:46 PM
To: coral-erm/coral
Cc: Hao Zeng; Comment
Subject: Re: [coral-erm/coral] Problem with SimpleXML processing COUNTER report namespaces. (#485)
EBSCO.
I just tried EBSCO BR2 and JR1 and it worked fine with the second changes. Can't remember which vendor was failing on the first set.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#485 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ALoQzGE2awxH0ZATE0nQ8R0SB9lappYiks5vX9DvgaJpZM4Wn476>.
|
The idea of stripping strings like "s:" from a random XML document strikes me as utter insanity. For example, if the data includes a title like "Enemies: a love story" then the title will be changed to "Enemie a love story". Not to mention that a namespace prefix such as "reports:" will be changed to "report" without the colon. The right solution is beyond me -- I don't know PHP well enough, least of all the quirks of SimpleXML -- but couldn't we at least make this bug slightly less nasty by registering some namespaces and using XPath? Something along the following lines: $ns = array( And so on? |
The namespaces are not standard across vendors. I tried reading all the namespaces and registering them but that didn't work. |
I agree, but I'm not trying to fix the bug, I'm just trying to mitigate the harm that it causes. The current code is just so entirely wrong -- the hack on line 610 would, for example, completely mangle a SUSHI response that happens to use a namespace prefix ending in "s" (other than the prefix "s:" itself): $clean_xml = str_ireplace(['s:','SOAP-ENV:','SOAP:'],'',$string); And registering the namespaces from an associative array as my code does should make it easier to add namespaces in the future. In fact, if you have a corpus of sushistore/*.xml that you're able to share, I would be happy to identify all namespaces used in them and adjust the array accordingly. You can just grep the files for : and send me that output -- I don't need anything else. |
I tried adding the namespaces, it didn't work for me. |
Perhaps we should just strip all namespaces from the XML, then proceed from there. You can strip namespaces like this: function stripNamespaces($xml) { Then you just make a small change in lines 609-611: $string = file_get_contents($fName); Hopefully that does the trick -- I haven't tested it yet. |
I have a sandbox instance where I can test the code in the pull request, but I have to set up a SUSHI connection in it first (and have never done that before) -- so if you have an instance you can test it in now, that would be great. |
@queryluke has a much better fix in #579 |
I have merged @queryluke 's fix for this issue, PR #611 |
PHP Warning: simplexml_load_string(): namespace error : Namespace prefix rr on Report is not defined in /var/www/html/coral3/usage/admin/classes/domain/SushiService.php on line 611, referer: /coral3/usage/sushi.php
PHP Fatal error: Call to a member function attributes() on null in /var/www/html/coral3/usage/admin/classes/domain/SushiService.php on line 630, referer: /coral3/usage/sushi.php
Traced these errors back to:
610 $clean_xml = str_ireplace(['s:','SOAP-ENV:','SOAP:'],'',$string);
611 $xml = simplexml_load_string($clean_xml);
and
629 $report = $xml->Body->ReportResponse->Report->Report;
630 $reportTypeName = $report->attributes()->Name;
These changes seem to fix it for me
610 (line deleted)
611 $xml = simplexml_load_string($string);
612 $xml->registerXPathNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
613 $xml->registerXPathNamespace("r", "http://www.niso.org/schemas/counter");
and
629 $report = $xml->xPath("s:Body//r:Report")[0];
The text was updated successfully, but these errors were encountered: