Salve amici, sto cercando di realizzare un file xml/kml dinamicamente per poi poterlo scaricare e aggiungere a Google Hearth!

La struttura da realizzare è la seguente:
codice:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
	<name>TEST Icon</name>
    <description>Description test</description>

  	<Style id="yellow">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/kml/...lw-pushpin.png</href>
        </Icon>
      </IconStyle>
    </Style>
    <Style id="blue">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/kml/...ue-pushpin.png</href>
        </Icon>
      </IconStyle>
    </Style>

	<Placemark>
    	<name>Casa JellyBelly</name>
		<styleUrl>#yellow</styleUrl>
    	<description>
			<![CDATA[
				<h1>CDATA Tags are useful!</h1>
				

<font color="red">Casa di Jelly a Piazzano</font></p>
			]]>
    	</description>
    	<Point>
			<coordinates>14.4112707,42.1273162
      		</coordinates>
    	</Point>
	</Placemark> 
	
  	<Placemark>
    	<name>Casa Sara</name>
		<styleUrl>#blue</styleUrl>
    	<description>Casa di Sara a Montemarcone
    	</description>
    	<Point>
      		<coordinates>14.4512208,42.1253950
      		</coordinates>
    	</Point>
  	</Placemark>	
</Document>
</kml>
Io ho iniziato l'implementazione ma ho subito trovato un'ostacolo. Vi posto il codice che ho scritto fin'ora:
Codice PHP:
public function generateKMLToMap($resellers){

        
header("Content-type: text/xml");
        
        
// Start XML file, create parent node
        
$dom = new DOMDocument("1.0");
        
        
$node $dom->createElement("kml");
        
$kmlnode $dom->appendChild($node); 
        
$kmlnode->setAttribute("xmlns""http://earth.google.com/kml/2.2");
         
        
        
$node $dom->createElement("Document");
        
$parnode $dom->appendChild($node); 
        
// Aggiungo a KML le info di default
        
$parnode->setAttribute("name"$resellers[0]->networkname);
        
$parnode->setAttribute("description""File KML contenente tutti i Reseller della Rete ".$resellers[0]->networkname);

        
//Aggiungo all'xml i reseller dove ci sono gli incarichi

        
foreach($resellers as $k => $v){  
            if(
$v->latlng != false){
                
$node $dom->createElement("Placemark");  
                
$newnode $parnode->appendChild($node);   

                
$newnode->setAttribute("name",$v->resellername);
                
$newnode->setAttribute("description"$v->address);

                
$newnode->setAttribute("Point"$v->latlng->lng.",".$v->latlng->lat);
            }
        }

        return 
$dom->saveXML();
    } 
se non inserisco questa porzione di codice:
Codice PHP:
$node $dom->createElement("kml");
        
$kmlnode $dom->appendChild($node); 
        
$kmlnode->setAttribute("xmlns""http://earth.google.com/kml/2.2"); 
non riesco proprio a capacitarmi del perchè non funziona con queste 3 righe in più!
Dovrebbe essere la stessa cosa!!!

Poi vi chiedo aiuto sulla realizzazione di questa porzione dell'xml:
codice:
<Style id="yellow">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/kml/...lw-pushpin.png</href>
        </Icon>
      </IconStyle>
    </Style>
Non ho la minima idea di come assegnare un id all'elemento!

Spero mi possiate aiutare!
Ciao a tutti e grazie in anticipo!!!