Loading KML file in to mysql / xpath and x quires

馋奶兔 提交于 2019-12-07 17:14:01

问题


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


回答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



来源:https://stackoverflow.com/questions/5341039/loading-kml-file-in-to-mysql-xpath-and-x-quires

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!