Note that there are some explanatory texts on larger screens.

plurals
  1. PODOM XPath Query Help
    primarykey
    data
    text
    <p>so this xpath query is driving me crazy. What I'm trying to do is search an xml file (in this case a kml file for use with the google maps api) of golf courses for a specific course type and grab each matching <code>&lt;Placemark&gt;</code> element so that i can create a new xml object with the results so that I can further filter with a new query. Problem is I can't seem to figure out how to get each matching <code>&lt;Placemark&gt;</code> element</p> <pre><code>$xml = '&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;kml xmlns="http://earth.google.com/kml/2.1"&gt; &lt;Document&gt; &lt;Placemark id="placemark3"&gt; &lt;name&gt;Test Country Club&lt;/name&gt; &lt;description&gt; &lt;![CDATA[ &lt;div class="contact"&gt;Post Office Box 329 &lt;a href="#" target="_blank"&gt;website&lt;/a&gt;&lt;/div&gt; ]]&gt; &lt;/description&gt; &lt;alpha&gt;a&lt;/alpha&gt; &lt;position&gt;2&lt;/position&gt; &lt;type&gt;Public/Daily Fee&lt;/type&gt; &lt;styleUrl&gt;#nineholeStyle&lt;/styleUrl&gt; &lt;Point&gt; &lt;coordinates&gt;-79.285576,37.111809&lt;/coordinates&gt; &lt;/Point&gt; &lt;/Placemark&gt; &lt;/Document&gt; &lt;/kml&gt;'; $dom = new DOMDocument(); $dom-&gt;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-&gt;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 } </code></pre> <p>Any help would be greatly appreciated. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload