Skip to content
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

Strip all namespaces from SUSHI responses #579

Closed

Conversation

nkuitse
Copy link
Contributor

@nkuitse nkuitse commented Apr 12, 2019

This is meant to close #485 but has not been tested.

@jeffnm jeffnm changed the base branch from master to development April 29, 2019 15:12
@jeffnm jeffnm added help wanted bug This is a bug (not an enhancement) labels Apr 29, 2019
@queryluke
Copy link
Contributor

I was doing some debugging for a Sirsi client and came across this same issue. The problem is that some publishers add namespaces to their SUSHI XML.

Coral removes some namespaces, but I've seen the following in my debugging: ns2, ns3, rr, d, np

Unfortunately, I could not get @nkuitse 's code to work on my development server. Instead I changed their stripNamespaces function to the following:

private function stripNamespaces($string) {
        $sxe = new SimpleXMLElement($string);
        $doc = new DOMDocument();
        $doc->loadXML($string);


        foreach ($sxe->getNamespaces(true) as $name => $uri) {
        	if(!empty($name)){
                $finder = new DOMXPath($doc);
                $nodes = $finder->query("//*[namespace::{$name} and not(../namespace::{$name})]");
                foreach ($nodes as $n) {
                    $ns_uri = $n->lookupNamespaceURI($name);
                    $n->removeAttributeNS($ns_uri, $name);
                }
			}
        }
        return $doc->saveXML(null, LIBXML_NOEMPTYTAG);
}

Or, you can see my branch here.
I've tested my code with the following vendors:

  • Brill
  • Cambridge University Press
  • Elsevier
  • Sage
  • Springer
  • Taylor and Francis

I can either make a new PR or if someone wants to request a change or confirm @nkuitse code works.

@nkuitse
Copy link
Contributor Author

nkuitse commented May 23, 2019

This fix by @queryluke seems much cleaner than mine in #485. Thanks!

@andyp-uk
Copy link
Contributor

I've tested @queryluke 's fix in PR #611 and this looks good so I've merged this. I think this PR can therefore be closed.

@andyp-uk andyp-uk closed this Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug (not an enhancement) help wanted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants