my $dom = XML::LibXML::Document->new('1.0', 'UTF-8'); my $kml = $dom->createElement('kml'); $kml->setAttribute('xmlns', 'http://earth.google.com/kml/2.1'); $dom->setDocumentElement($kml); my $document = $dom->createElement('Document'); $kml->appendChild($document);