Maybe another suitable format could be GeoJSON. PostGIS can return edge geometries in GeoJSON format with ST_AsGeoJSON
, so all you need to do is wrapping all edges into a GeoJSON "FeatureCollection".
You can find a simple example in the pgRouting workshop: http://workshop.pgrouting.org/chapters/php_server.html#geojson-output
You can create KML, GML, GPX or other formats in a similar way, but GeoJSON is probably the easiest one.
Update:
If you need GPX, how does your file look like? Like this should be correct:
<?xml version="1.0" encoding="UTF-8"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
creator="" version="1.1">
<metadata>[...]</metadata>
<trk>
<name>Track name</name>
<!-- Loop through your edge segments -->
<trkseg>
[List of points]
<extensions></extensions>
</trkseg>
<!-- Loop end -->
</trk>
</gpx>
<trkseg>
is described in http://www.topografix.com/GPX/1/1/#type_trksegType.
You need to modify your PostgreSQL query and put the geometry in the right list format for each edge.