src/OaiPmh/RecordXmlFormatter.php
protected function fixNamespaces($xml, $ns, $attr = '')
    {
        foreach ($ns as $key => $val) {
            if (!empty($key)
                && strstr($xml, $key . ':') && !strstr($xml, 'xmlns:' . $key)
                && !strstr($attr, 'xmlns:' . $key)
            ) {
                $attr .= ' xmlns:' . $key . '="' . $val . '"';
            }
        }
        if (!empty($attr)) {
            $xml = preg_replace('/>/', ' ' . $attr . '>', $xml, 1);
        }
        return $xml;
    }
protected function fixNamespaces($xml, $ns, $attr = '')
    {
        foreach ($ns as $key => $val) {
            if (!empty($key)
                && strstr($xml, $key . ':') && !strstr($xml, 'xmlns:' . $key)
                && !strstr($attr, 'xmlns:' . $key)
            ) {
                $attr .= ' xmlns:' . $key . '="' . $val . '"';
            }
        }
        if (!empty($attr)) {
            $xml = preg_replace('/>/', ' ' . $attr . '>', $xml, 1);
        }
        return $xml;
    }
protected function fixNamespaces ( $ xml , $ ns , $ attr = '' ) { foreach ( $ ns as $ key => $ val ) { if ( ! empty ( $ key ) && strstr ( $ xml , $ key . ':' ) && ! strstr ( $ xml , 'xmlns:' . $ key ) && ! strstr ( $ attr , 'xmlns:' . $ key ) ) { $ attr .= ' xmlns:' . $ key . '="' . $ val . '"' ; } } if ( ! empty ( $ attr ) ) { $ xml = preg_replace ( '/>/' , ' ' . $ attr . '>' , $ xml , 1 ) ; } return $ xml ; }
Fix namespaces in the top tag of the XML document to compensate for bugs
in the SimpleXML library.

@param string $xml  XML document to clean up
@param array  $ns   Namespaces to check
@param string $attr Attributes extracted from the <metadata> tag

@return string
Fix namespaces in the top tag of the XML document to compensate for bugs in the SimpleXML library .