I am trying to parse an KML-File in PHP and parse it using JavaScript. Now I have tried different approaches so far. My problem is, that I seem not to be able to remove every line break from the "xml". With the following method I could force all XML in one line but failed to remove spaces from "<![CDATA[....
"
$dom = new DOMDocument();
$dom->preserveWhitespaces = false;
$dom->load("FILE-URL goes here");
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//text()') as $domText) {
$domText->data = trim(str_replace("\r\n","",$domText->nodeValue));
}
$dom->formatOutput = true;
$string = $dom->saveHTML();
With my next try I was able to convert everything into a string, but unable to remove any line breaks from it:
$xml = simplexml_load_file("FILE-URL goes here", 'SimpleXMLElement', LIBXML_NOCDATA);
$string = (string)$xml->asXML();
print_r(trim(preg_replace("/\r\n\t+/","",$string)));
Removing the breaks is necessary for the following JS code to be executed:
geoXml.parseKmlString('<?php print(STRING FROM ABOVE) ?>');
Unfortunately I can't download files onto the server so I am bound to something like the above. Also I can't use PHP to display the map. The KML-File itself is a normal Google-Maps-KML-File.