Installation

_$: apt-get install xmlstarlet

Queries

<?xml version="1.0" encoding="utf-8"?>
<properties xmlns="http://www.example.com">
  <property>
    <property-type>commercial</property-type>
    ...
    <location>
        ...
        <town>Madrid</town>
        <latitude>40.4167047</latitude>
        <longitude>-3.7035825</longitude>
  </property>
  ...
</properties>

All cities:

_$: xmlstarlet sel -N x="http://www.example.com" \
  -t -m '/x:properties/x:property/x:location/x:town' \
  -v 'text()' -n last.xml
_$: xmlstarlet sel -N x="http://www.taloki.com" \
  -t -m '//x:town' \
  -v 'text()' -n last.xml

Latitude and longitude of all properties in the city of Madrid:

_$: xmlstarlet sel -N x="http://www.example.com" \
  -t -m '/x:properties/x:property/x:location/x:town[text()="Madrid"]/parent::*/*[self::x:town or self::x:latitude or self::x:longitude]' \
  -v 'text()' -n last.xml

All properties in Madrid:

_$: xmlstarlet sel -N x="http://www.example.com" \
  -t -c '/x:properties/x:property/x:location/x:town[text()="Madrid"]/parent::*/parent::*' ./last.xml

Remove all properties not located in Adra:

_$: xmlstarlet ed -N x="http://www.taloki.com" \
  -d '//x:property[x:location[x:town != "Adra"]]' last.xml