所以這個xpath查詢讓我瘋狂。我試圖做的是搜索一個特定課程類型的高爾夫球場的xml文件(在這種情況下,一個kml文件用於谷歌地圖api),並抓住每個匹配的<Placemark>
元素,以便我可以創建一個新的xml對象與結果,以便我可以進一步篩選一個新的查詢。問題是,我似乎無法弄清楚如何讓每一個匹配<Placemark>
元素DOM XPath查詢幫助
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Placemark id="placemark3">
<name>Test Country Club</name>
<description>
<![CDATA[
<div class="contact">Post Office Box 329 <a href="#" target="_blank">website</a></div>
]]>
</description>
<alpha>a</alpha>
<position>2</position>
<type>Public/Daily Fee</type>
<styleUrl>#nineholeStyle</styleUrl>
<Point>
<coordinates>-79.285576,37.111809</coordinates>
</Point>
</Placemark>
</Document>
</kml>';
$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
//trying to get any Placemark element where type child matches a specific query
//in this case we want to search for Public/Daily Fee and return the placemark and everything inside it.
$query = $xpath->query("//Placemark[type='Public/Daily Fee']/ancestor::Placemark");;
foreach ($query as $result) {
//eventually want to merge each result into new xml object to be further filtered
}
任何幫助將不勝感激。謝謝
[將KML文件加載到mysql/xpath和x quires中](http://stackoverflow.com/questions/5341039/loading-kml-file-in-to-mysql-xpath-and-x- quires) – 2011-03-17 16:36:42
@Alejando是真的,但它沒有答案。那麼可能應該合併。 – Gordon 2011-03-17 16:37:52