3

hello im coming across a few problems on loading a large kml file i was originally using cold fusion but it just cant handle the large xml/kml files

so i thought id give it a bash using php i am fairly new to php and coldfusion

so you can get the kmz file ive been working on from http://marinetraffic2.aegean.gr/ais/getkml.aspx you will have to rename it to .zip then expand it there should be a kml file in there called doc.kml change it to xml and there you go there is a Bom at the start of it i got round that on the cfhttp and type=ut-8 thingy then removing the first 3 chars

now the part i am having problems with is loading the xpaths or any queries on it

i would like to put this is to an array to work with before i put it in to a data base there colums that i need are name coordinates styleurl and descriptions

i have manged to get this but to work

$dom = new DomDocument();
$dom->load("http://localhost/testdocs/bigdoc.xml");
$titles = $dom->getElementsByTagName("coordinates");

foreach($titles as $node) {
   print $node->textContent . "<br> ";
}

this will return the list of names in the xml file

but thats all of them the path that i need would be kml/Document/Folder/Placemark/ (name yada yada)

can someone with a fresh pair of eyes

the bit in cold fusion just hanged there for ages but when i tried on the same much smaller file it worked

so im new to php but that little bit of code works on the large file unlike cold fusion

okey the main problem is that xpaths queries are just not working past the /folder

i hope you can kinda understand my ramblings

thanks for your help in advanced JC

Ocaso Protal
  • 19,362
  • 8
  • 76
  • 83
  • @james cleverly: Did you register the namespace URI `http://earth.google.com/kml/2.1` with a prefix (say `kml`, i.e.)with your XPath engine? Did you use a prefixed QName test like `kml:kml/kml:Document/kml:Folder/kml:Placemark`? –  Mar 17 '11 at 16:34
  • have you got any sample code to do that how would i register this with cold fusion or php thanks for the response tho chap i think were heading in the right direction – james cleverly Mar 17 '11 at 22:46
  • @james cleverly: Take a look at http://stackoverflow.com/questions/3719616/xpath-finds-nothing-but –  Mar 17 '11 at 22:50
  • ok i think were getting there and i think my lack of knowledge of php is starting thanks for the post Alejandro ` $newXML = simplexml_load_file("http://localhost/testdocs/bigdoc.xml"); var_dump($newXML->xpath("//*[local-name() = 'Placemark']"));` thats starting to work im getting results on my page looks like this array(23367) { [0]=> object(SimpleXMLElement)#2 (4) { ["name"]=> string(8) "EEMSHORN" ["styleUrl"]=> string(56) "http://www.marinetraffic.com/ais/stylekml. the values i am after are name styleurl and description any one know how i loop through this or or dump each value in tosql – james cleverly Mar 18 '11 at 11:14
  • just an addion did this in coldfusion with the new found xpathbit ' ' and i get a wounderfull out of head space just great its only 15mb – james cleverly Mar 18 '11 at 11:37
  • so anyone know how i get this in sql – james cleverly Mar 22 '11 at 10:22

1 Answers1

1

DomDocument() is very expensive in terms of resources. I use XMLReader() to parse very large XML files ( > 600MB) without problems.

Take a look at the documentation: http://php.net/manual/en/book.xmlreader.php

Fulippo
  • 31
  • 3