$openSearchDetailXML->registerXPathNamespace("gts", "http://www.isotc211.org/2005/gts");
$openSearchDetailXML->registerXPathNamespace("srv", "http://www.isotc211.org/2005/srv");
$openSearchDetailXML->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
//check if only iso19139 data is requested - if so - push the result automatically from the CSW getRecordById request to the user or the validator
if ($_REQUEST['mdtype'] == 'iso19139' && $_REQUEST['validate'] != 'true') {
    header("Content-type: application/xhtml+xml; charset=UTF-8");
    //delete scw entries from response file
    $MD_Metadata = str_replace('<csw:GetRecordByIdResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">', '', $openSearchDetail);
    $MD_Metadata = str_replace('</csw:GetRecordByIdResponse>', '', $MD_Metadata);
    echo $MD_Metadata;
    die;
}
if ($_REQUEST['mdtype'] == 'iso19139' && $_REQUEST['validate'] == 'true') {
    $MD_Metadata = str_replace('<csw:GetRecordByIdResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">', '', $openSearchDetail);
    $MD_Metadata = str_replace('</csw:GetRecordByIdResponse>', '', $MD_Metadata);
    validateInspireMetadataFromData($MD_Metadata);
}
$j = 0;
switch ($os_list[0]['version']) {
    case 2:
        //register namespaces:
        /* <gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:srv="http://www.isotc211.org/2005/srv" id="_ingrid-group_iplug-rp-udk-db_263">*/
        for ($a = 0; $a < count($md_ident); $a++) {
            $resultOfXpath = $openSearchDetailXML->xpath('/csw:GetRecordByIdResponse' . $md_ident[$a]['iso19139']);
            for ($i = 0; $i < count($resultOfXpath); $i++) {
                $md_ident[$a]['value'] = $md_ident[$a]['value'] . "," . $resultOfXpath[$i];
            }
            $md_ident[$a]['value'] = ltrim($md_ident[$a]['value'], ',');
        }
        break;
    default:
        } else {
            //send error report - metadata has not been harvested - maybe
            $errMsg = "Metadata should have been harvested, but some unkown error occured";
            echo $errMsg;
            die;
        }
        break;
    case 'capabilities':
        //do the same as for the external case but all from caps should be harvested
        if ($mb_metadata['harvestresult'] == 1) {
            if ($_REQUEST['VALIDATE'] != "true") {
                header("Content-type: text/xml");
                echo $mb_metadata['data'];
                die;
            } else {
                validateInspireMetadataFromData($mb_metadata['data']);
                die;
            }
        } else {
            //send error report - metadata has not been harvested - maybe
            $errMsg = "Metadata should have been harvested, but some unkown error occured";
            $errMsg .= "<br>Please use following URL directly: <a href='" . $mb_metadata['link'] . "'>" . $mb_metadata['link'] . "</a><br>";
            echo $errMsg;
            die;
        }
    default:
        break;
}
//function to give away the xml data
function pushISO19139($iso19139Doc, $recordId)
{