Skip to content
This repository

Fixing XML Validation failure #221

Merged
merged 3 commits into from over 2 years ago

3 participants

Pierre GIRAUD Andreas Hocevar Éric Lemoine
Pierre GIRAUD
Owner

The generated GPX files was not valid according to the schema. This pull request fixes this. Please review.

lib/OpenLayers/Format/GPX.js
@@ -71,6 +71,13 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, {
71 71 * "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
72 72 */
73 73 schemaLocation: "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd",
  74 +
  75 + /**
  76 + * Property: creator
1
Éric Lemoine Owner

This should be an APIProperty I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Andreas Hocevar
Owner

Very good catch!

Andreas Hocevar
Owner

Looks good to me, also with creator not being an API property. Please merge if @elemoine agrees and tests pass.

Éric Lemoine
Owner

@ahocevar it makes sense for the application developer to be able to change the creator, that's why I suggested to make it an API option.

Pierre GIRAUD pgiraud merged commit cd41548 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 15 additions and 7 deletions. Show diff stats Hide diff stats

  1. +9 1 lib/OpenLayers/Format/GPX.js
  2. +6 6 tests/Format/GPX.html
10 lib/OpenLayers/Format/GPX.js
@@ -71,6 +71,13 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, {
71 71 * "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
72 72 */
73 73 schemaLocation: "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd",
  74 +
  75 + /**
  76 + * APIProperty: creator
  77 + * {String} The creator attribute to be added to the written GPX files.
  78 + * Defaults to "OpenLayers"
  79 + */
  80 + creator: "OpenLayers",
74 81
75 82 /**
76 83 * Constructor: OpenLayers.Format.GPX
@@ -218,8 +225,9 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, {
218 225 write: function(features, metadata) {
219 226 features = OpenLayers.Util.isArray(features) ?
220 227 features : [features];
221   - var gpx = this.createElementNSPlus("gpx:gpx");
  228 + var gpx = this.createElementNS(this.namespaces.gpx, "gpx");
222 229 gpx.setAttribute("version", "1.1");
  230 + gpx.setAttribute("creator", this.creator);
223 231 this.setAttributes(gpx, {
224 232 "xsi:schemaLocation": this.schemaLocation
225 233 });
12 tests/Format/GPX.html
@@ -46,7 +46,7 @@
46 46 new OpenLayers.Feature.Vector(point2, {name: 'foo', description: 'bar'})
47 47 ];
48 48 var data = parser.write(features);
49   - t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wpt lon="-111.04" lat="45.68"><name>foo</name><desc>bar</desc></wpt><wpt lon="-112.04" lat="45.68"><name>foo</name><desc>bar</desc></wpt></gpx>', 'GPX serializes points correctly');
  49 + t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="OpenLayers" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wpt lon="-111.04" lat="45.68"><name>foo</name><desc>bar</desc></wpt><wpt lon="-112.04" lat="45.68"><name>foo</name><desc>bar</desc></wpt></gpx>', 'GPX serializes points correctly');
50 50 }
51 51 function test_Format_GPX_serialize_line(t) {
52 52 t.plan(1);
@@ -58,7 +58,7 @@
58 58 var line = new OpenLayers.Geometry.LineString([point, point2]);
59 59 var f = new OpenLayers.Feature.Vector(line, {name: 'foo', description: 'bar'});
60 60 var data = parser.write(f);
61   - t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/></trkseg></trk></gpx>', 'GPX serializes line correctly');
  61 + t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="OpenLayers" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/></trkseg></trk></gpx>', 'GPX serializes line correctly');
62 62 }
63 63 function test_Format_GPX_serialize_lines(t) {
64 64 t.plan(1);
@@ -74,7 +74,7 @@
74 74 var f = new OpenLayers.Feature.Vector(line, {name: 'foo', description: 'bar'});
75 75 var f2 = new OpenLayers.Feature.Vector(line2, {name: 'dude', description: 'truite'});
76 76 var data = parser.write([f, f2]);
77   - t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/></trkseg></trk><trk><name>dude</name><desc>truite</desc><trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/></trkseg></trk></gpx>', 'GPX serializes lines correctly');
  77 + t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="OpenLayers" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/></trkseg></trk><trk><name>dude</name><desc>truite</desc><trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/></trkseg></trk></gpx>', 'GPX serializes lines correctly');
78 78 }
79 79 function test_Format_GPX_serialize_multiline(t) {
80 80 t.plan(1);
@@ -90,7 +90,7 @@
90 90 var multiline = new OpenLayers.Geometry.MultiLineString([line, line2]);
91 91 var f = new OpenLayers.Feature.Vector(multiline, {name: 'foo', description: 'bar'});
92 92 var data = parser.write([f]);
93   - t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/></trkseg><trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/></trkseg></trk></gpx>', 'GPX serializes multiline correctly');
  93 + t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="OpenLayers" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/></trkseg><trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/></trkseg></trk></gpx>', 'GPX serializes multiline correctly');
94 94 }
95 95 function test_Format_GPX_serialize_polygon(t) {
96 96 t.plan(1);
@@ -103,7 +103,7 @@
103 103 var polygon = new OpenLayers.Geometry.Polygon([linearRing]);
104 104 var f = new OpenLayers.Feature.Vector(polygon, {name: 'foo', description: 'bar'});
105 105 var data = parser.write([f]);
106   - t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/><trkpt lon="-111.04" lat="45.68"/></trkseg></trk></gpx>', 'GPX serializes polygon correctly');
  106 + t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="OpenLayers" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/><trkpt lon="-111.04" lat="45.68"/></trkseg></trk></gpx>', 'GPX serializes polygon correctly');
107 107 }
108 108 function test_Format_GPX_serialize_metadata(t) {
109 109 t.plan(1);
@@ -111,7 +111,7 @@
111 111 var parser = new OpenLayers.Format.GPX();
112 112
113 113 var data = parser.write([], {name: 'foo', desc: 'bar'});
114   - t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><metadata><name>foo</name><desc>bar</desc></metadata></gpx>', 'GPX serializes metadata correctly');
  114 + t.xml_eq(data, '<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="OpenLayers" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><metadata><name>foo</name><desc>bar</desc></metadata></gpx>', 'GPX serializes metadata correctly');
115 115 }
116 116 </script>
117 117 </head>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.