Skip to content

Commit 5a115b0

Browse files
committed
GpxFile.BuildString omits duplicate namespaces.
Resolves #33
1 parent 2692940 commit 5a115b0

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

doc/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [0.5.0](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/milestone/10)
44
- `GpxWriterSettings.TimeZoneInfo` is no longer completely ignored ([#30](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/issues/30)).
55
- Fix an issue where written timestamps were being rounded to the nearest second instead of preserving as many significant digits as `DateTime` allows ([#31](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/issues/31)).
6+
- Tweak the settings used for `GpxFile.BuildString` to avoid repeating the `xmlns` declaration for extensions that are declared in the standard GPX namespace ([#33](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/issues/33)).
67

78
## [0.4.0](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/milestone/7)
89
- `GpxReaderSettings` now has an `IgnoreBadDateTime` property to use for ignoring a timestamp value that we cannot parse as an instance of the `DateTime` struct, to work around a `0000-00-00T00:00:00Z` coming from CompeGPS ([#29](https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/issues/29)).

src/NetTopologySuite.IO.GPX/GpxFile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public sealed class GpxFile
2626
Indent = true,
2727
NewLineOnAttributes = true,
2828
OmitXmlDeclaration = true,
29+
NamespaceHandling = NamespaceHandling.OmitDuplicates,
2930
};
3031

3132
private GpxMetadata metadata = new GpxMetadata(creator: "NetTopologySuite.IO.GPX");

tests/NetTopologySuite.IO.GPX.Tests/GpxFileTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Linq;
44
using System.Text;
5+
using System.Text.RegularExpressions;
56
using System.Xml;
67
using System.Xml.Linq;
78

@@ -348,5 +349,22 @@ public void TimestampsShouldPreserveFractionalSecondsWithinDefinedPrecision()
348349
Assert.Contains("5432-10-10T11:22:33.8765432Z", text); // DateTime resolution is 100ns, so the value gets rounded to 7 digits
349350
Assert.Contains("1111-11-11T11:11:11.12345Z", text); // don't output extra zeroes
350351
}
352+
353+
[Fact]
354+
[Regression]
355+
[GitHubIssue(33)]
356+
public void ExtensionsElementInGpxNamespaceShouldNotRepeatNamespaceSpecByDefault()
357+
{
358+
const string GpxText = @"
359+
<gpx xmlns='http://www.topografix.com/GPX/1/1' version='1.1' creator='airbreather'>
360+
<extensions><myTest someData='4' /></extensions>
361+
</gpx>
362+
";
363+
string text = GpxFile.Parse(GpxText, null).BuildString(null);
364+
365+
// be careful when using regex to match XML.
366+
var namespaceWasRepeatedRegex = new Regex("<extensions>.*topografix.*</extensions>", RegexOptions.Singleline);
367+
Assert.DoesNotMatch(namespaceWasRepeatedRegex, text);
368+
}
351369
}
352370
}

0 commit comments

Comments
 (0)