Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <strong>DOMDocument</strong> from <strong>PHP</strong>.</p> <p>You load your file and than loop trough the <strong>childNodes</strong> of the document.</p> <pre><code>&lt;?php $dom=new DOMDocument(); $dom-&gt;load("file.xml"); $root=$dom-&gt;documentElement; // This can differ (I am not sure, it can be only documentElement or documentElement-&gt;firstChild or only firstChild) $nodesToDelete=array(); $markers=$root-&gt;getElementsByTagName('marker'); // Loop trough childNodes foreach ($markers as $marker) { $type=$marker-&gt;getElementsByTagName('type')-&gt;item(0)-&gt;textContent; $title=$marker-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;textContent; $address=$marker-&gt;getElementsByTagName('address')-&gt;item(0)-&gt;textContent; $latitude=$marker-&gt;getElementsByTagName('latitude')-&gt;item(0)-&gt;textContent; $longitude=$marker-&gt;getElementsByTagName('longitude')-&gt;item(0)-&gt;textContent; // Your filters here // To remove the marker you just add it to a list of nodes to delete $nodesToDelete[]=$marker; } // You delete the nodes foreach ($nodesToDelete as $node) $node-&gt;parentNode-&gt;removeChild($node); echo $dom-&gt;saveXML(); ?&gt; </code></pre> <p>You can save your output XML like this</p> <pre><code>$dom-&gt;saveXML(); // This will return the XML as a string $dom-&gt;save('file.xml'); // This saves the XML to a file </code></pre> <p>To do this parsing in <strong>JavaScript</strong> you should use <a href="http://jquery.com/" rel="noreferrer" title="jQuery">jQuery</a> (a small, but powerful library).</p> <p>You can include the library directly from Google Code Repository.</p> <pre><code>&lt;script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"&gt;&lt;/script&gt; </code></pre> <p><em>The library is cross-browser and very small. It should be cached in many cases, because some sites use it from Google Code</em></p> <pre><code>$(yourXMLStringOrDocument).find("marker").each(function () { var marker=$(this); var type=marker.find('type').text(); var title=marker.find('title').text(); var address=marker.find('address').text(); var latitude=marker.find('latitude').text(); var longitude=marker.find('longitude').text(); }); </code></pre>
 

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