XMLStarlet

From OpenStreetMap Wiki
Jump to navigation Jump to search

XMLStarlet is a command-line tool for procession XML files using XPath. It can be used for manipulating .osm-files.

Examples

Delete all created_by=* tags:

$ xmlstarlet ed -d "//tag[@k='created_by']" < input.osm > output.osm

Remove "deleted" objects from a JOSM-saved .osm-file:

$ xmlstarlet ed -d "/osm/*[@action='delete']" < input.osm > output.osm

As above, but also remove other action-tags:

$ xmlstarlet ed -d "/osm/*[@action='delete']" -d "/osm/*/@action" < input.osm > output.osm

Get the timestamp of the last undeleted version of a way from its history:

$ wget -O wayhist.osm https://openstreetmap.org/api/0.6/way/24404237/history
$ xmlstarlet  sel  -t -m "/osm/way[@visible='true'][last()]" -c "string(@timestamp)"  wayhist.osm