Buenas,
No duplico la etiqueta <html> 
El primer script es este. Al final, incluye sitemap.xml y es donde se produce el error:    
Código PHP:
Ver original<!DOCTYPE html>
<html lang="es">
<?php
    // BBDD
    include("includes/inc_conexion.php"); 
    include("includes/inc_config.php"); 
        
    $xml_file = 'fincamps_HS/500190_UN.XML';
    }
    else 
        exit("Error a l'intentar obrir el fitxer ".$xml_file);  
    foreach ($xml->Registro as $Registro) {  
        $qry = "INSERT INTO t_un "."( id_piso, referencia, operacion, tipo, familia, poblacion, situacion1, situacion2, precio, habitaciones, metros, estado, CodigoPostal, DireccionInmueble, AbreviacionTipoCalle, NombreCalleInmueble, AbreviacionTipoNumero, NumeroCalleInmueble, CertificacionEnergetica, PrestacionEnergetica, CertificacionEmisiones, PrestacionEmisiones, Moll_box, Grua_box)".
            " VALUES ('$Registro->IdPiso', "."'".addslashes($Registro->Expediente)."', ".                 "'".addslashes($Registro->IdFamiliaTipoInmueble)."', "."'".addslashes($Registro->IdPoblacion)."', ".                 "'".addslashes($Registro->Hdobles_num+$Registro->Hsimples_num)."', ".                 "'".addslashes($Registro->SuperficieTotal)."', "."".$estado.", ".                 "'".addslashes($Registro->AbreviacionTipoCalle)."', "."'".addslashes($Registro->NombreCalleInmueble)."', ".                 "'".addslashes($Registro->AbreviacionTipoNumero)."', "."'".addslashes($Registro->NumeroCalleInmueble)."', ".                 "'".addslashes($Registro->CertificacionEnergetica)."', "."'".addslashes($Registro->PrestacionEnergetica)."', ".                 "'".addslashes($Registro->CertificacionEmisiones)."', "."'".addslashes($Registro->PrestacionEmisiones)."', ".         // canviar a php.ini: php_value max_execution_time 90 i posar 30
        if ($Registro->Foto1 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto1)."')";         }
        if ($Registro->Foto2 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto2)."')";         }
        if ($Registro->Foto3 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto3)."')";         }
        if ($Registro->Foto4 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto4)."')";         }
        if ($Registro->Foto5 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto5)."')";         }
        if ($Registro->Foto6 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto6)."')";         }
        if ($Registro->Foto7 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto7)."')";         }
        if ($Registro->Foto8 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto8)."')";         }
        if ($Registro->Foto9 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto9)."')";         }
        if ($Registro->Foto10 != "") {
            $qry = "INSERT INTO t_fotos (referencia, foto) VALUES ('".addslashes($Registro->Expediente)."', '".addslashes($Registro->Foto10)."')";         }
    }
    echo "Un".'<br>';
        
?>
 
</html>
 
 
<?php   include("sitemap.php");  
?>
  
Y el segundo script, sitemap.xml es este:    
Código PHP:
Ver original<?php 
    header('Content-Type: application/xml');  
    function eliminaAccentos($String)
    {
        return $String;
    
    }
    
    
    $codigo = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
    $codigo .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'."\n";
 
    $codigo .= '<url><loc>http://xxxx.es/</loc></url>'."\n";
    $codigo .= '<url><loc>http://xxxx.es/inmuebles-singulares</loc></url>'."\n";
    
    $consulta = "SELECT t_un.tipo, t_un.operacion, t_tipo.nombre_tipo_es, t_tipo.nombre_tipo_ca, t_operacion.operacion_tipo_es, t_poblacion.nombre_poblacion, t_un.situacion1, t_un.referencia ".
            "FROM t_un, t_operacion, t_tipo, t_poblacion ".
            "WHERE t_un.operacion = t_operacion.id_operacion AND t_un.tipo = t_tipo.id_tipo AND t_un.poblacion = t_poblacion.id_poblacion ".
            "ORDER BY t_un.familia, t_un.tipo, t_un.operacion, t_un.poblacion";
    if ($registros > 0){ 
            $pagina_ca = "<url><loc>http://xxxx.es/";
            $pagina_es = "<url><loc>http://xxxx.es/";
            switch ($fila['tipo']) {
                case 3:
                    $pagina_ca .= 'pisos-cases/';
                    $pagina_es .= 'pisos-casas/';
                    break;
                case 4:
                    $pagina_ca .= 'pisos-cases/';
                    $pagina_es .= 'pisos-casas/';
                    break;
                case 5:
                    $pagina_ca .= 'solars-parceles/';
                    $pagina_es .= 'solares-parcelas/';
                    break;
                case 6:
                    $pagina_ca .= 'naus-industrials/';
                    $pagina_es .= 'naves-industriales/';
                    break;
                case 7:
                    $pagina_ca .= 'locals-oficines/';
                    $pagina_es .= 'locales-oficinas/';
                    break;
                case 8:
                    $pagina_ca .= 'parquings/';
                    $pagina_es .= 'parkings/';
                    break;
                case 9:
                    $pagina_ca .= 'immobles-singulars/';
                    $pagina_es .= 'inmuebles-singulares/';
                    break;
                case 0:
                    $pagina_ca .= 'oportunitats-bancaries/';
                    $pagina_es .= 'oportunidades-bancarias/';
                    break;
            }
            if ($fila['operacion'] == 3) {
                $pagina_ca .= "lloguer/".trim(strtolower($fila['nombre_tipo_ca']))."-en-lloguer-";                 $pagina_es .= "alquiler/".trim(strtolower($fila['nombre_tipo_es']))."-en-alquiler-";             }
            else {          
                $pagina_ca .= "venda/".trim(strtolower(eliminaAccentos
($fila['nombre_tipo_ca'])))."-en-venda-";                 $pagina_es .= "venta/".trim(strtolower(eliminaAccentos
($fila['nombre_tipo_es'])))."-en-venta-";             }
            $pagina_ca .= eliminaAccentos
(strtolower($fila['nombre_poblacion']));             $pagina_es .= eliminaAccentos
(strtolower($fila['nombre_poblacion']));             if ($fila['situacion1'] != '') {
                $pagina_ca .= '-'.eliminaAccentos
(strtolower(trim($fila['situacion1'])));                 $pagina_es .= '-'.eliminaAccentos
(strtolower(trim($fila['situacion1'])));             }
            $pagina_ca .= '-'.$fila['referencia'].'.html'.'</loc></url>'."\n";
            $pagina_es .= '-'.$fila['referencia'].'.html'.'</loc></url>'."\n";
            
            $codigogo .= $pagina_ca.$pagina_es;
        }
    }
    $codigogo .= "</urlset>";
 
    if ($fitxer = fopen("sitemap.xml", "w+")) {     }
    else
        echo "error"; 
?>
  
Gracias