From: Markus Heidelberg Date: Mon, 10 Aug 2015 18:07:23 +0000 (+0100) Subject: Make notes GPX valid and add useful official elements X-Git-Tag: live~4646 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/166dc76ae94de4b07b32836e6db938e4040eaf09?hp=81d79f5e1671e1832c02576e1e0eed222bfb2bf6 Make notes GPX valid and add useful official elements The "creator" attribute is required and "extensions" is the correct name of this element. Validated with SAXCount from the xerces-c package: $ SAXCount -v=always -n -s -f notes.gpx Original error messages: Error at file /home/markus/notes.gpx, line 2, char 171 Message: no declaration found for element 'gpx' Error at file /home/markus/notes.gpx, line 2, char 171 Message: attribute 'version' is not declared for element 'gpx' After adding the "xmlns" attribute: Error at file /home/markus/notes.gpx, line 2, char 213 Message: missing required attribute 'creator' Error at file /home/markus/notes.gpx, line 18, char 14 Message: no declaration found for element 'extension' Error at file /home/markus/notes.gpx, line 26, char 7 Message: element 'extension' is not allowed for content model '(ele?,time?,magvar?,geoidheight?,name?,cmt?,desc?,src?,link*,sym?,type?,fix?,sat?,hdop?,vdop?,pdop?,ageofdgpsdata?,dgpsid?,extensions?)' The current errors now are caused by the missing XML schema for the extensions. Also add the time, name and link elements. --- diff --git a/app/views/notes/_note.gpx.builder b/app/views/notes/_note.gpx.builder index a55ed88f6..8a96db81c 100644 --- a/app/views/notes/_note.gpx.builder +++ b/app/views/notes/_note.gpx.builder @@ -1,9 +1,14 @@ xml.wpt("lon" => note.lon, "lat" => note.lat) do + xml.time note.created_at.to_s(:iso8601) + xml.name t("browse.note.title", :id => note.id) + xml.desc do xml.cdata! render(:partial => "description", :object => note, :formats => [ :html ]) end - xml.extension do + xml.link("href" => browse_note_url(note, :host => SERVER_URL)) + + xml.extensions do xml.id note.id xml.url note_url(note, :format => params[:format]) diff --git a/app/views/notes/index.gpx.builder b/app/views/notes/index.gpx.builder index 5a7f34dbd..5207ec3f8 100644 --- a/app/views/notes/index.gpx.builder +++ b/app/views/notes/index.gpx.builder @@ -1,6 +1,8 @@ xml.instruct! xml.gpx("version" => "1.1", + "creator" => "OpenStreetMap.org", + "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") do xml << (render(:partial => "note", :collection => @notes) || "") diff --git a/app/views/notes/show.gpx.builder b/app/views/notes/show.gpx.builder index e54d77246..8bb6c9688 100644 --- a/app/views/notes/show.gpx.builder +++ b/app/views/notes/show.gpx.builder @@ -1,6 +1,8 @@ xml.instruct! xml.gpx("version" => "1.1", + "creator" => "OpenStreetMap.org", + "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") do xml << render(:partial => "note", :object => @note) diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index b0fc3e1ee..8dc0866da 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -510,7 +510,7 @@ class NotesControllerTest < ActionController::TestCase assert_equal "application/gpx+xml", @response.content_type assert_select "gpx", :count => 1 do assert_select "wpt[lat='#{notes(:open_note).lat}'][lon='#{notes(:open_note).lon}']", :count => 1 do - assert_select "extension", :count => 1 do + assert_select "extensions", :count => 1 do assert_select "id", notes(:open_note).id assert_select "url", note_url(notes(:open_note), :format => "gpx") assert_select "comment_url", comment_note_url(notes(:open_note), :format => "gpx")