Kml getElementByNamTag error

When the KML file is read from the server it is a string and the OpenLayer KML parser is not able to retrieve the geometry. When the file is read locally it is a "#document" element. I added a DOMParser to transform the string and it solve the problem.