所以这个xpath查询让我抓狂.我正在尝试做的是搜索一个特定课程类型的高尔夫球场的xml文件(在这种情况下是与谷歌地图api一起使用的kml文件)并抓取每个匹配的<Placemark>元素,以便我可以创建一个新的xml对象结果,以便我可以进一步使用新查询进行过滤.问题是我似乎无法弄清楚如何获得每个匹配<Placemark>元素
$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 …Run Code Online (Sandbox Code Playgroud)