It would be better to generate the full KML file with the schemas like in:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
I note there is no support for the Google extensions (xmlns:gx="http://www.google.com/kml/ext/2.2"), would you be interested in these?