NetTopologySuite / NetTopologySuite.IO.GPX

GPX I/O for NetTopologySuite
BSD 3-Clause "New" or "Revised" License
10 stars 3 forks source link

How can we add custom namespace declarations to gpx element? #36

Closed lorenh closed 4 years ago

lorenh commented 5 years ago

Is injecting a custom namespace similar to the following possible when writing a GPX with this library?

<gpx version ="1.1"
          xmlns="http://www.topografix.com/GPX/1/1"
          xmlns:ABC="http://www.mycustomnamespace.net/xml">
:
</gpx>
airbreather commented 5 years ago

Not at the top level; the only place where you have an opportunity to inject custom stuff like that is when we go to write out the children of <extensions> elements.

Essentially, you'd make a subclass of GpxExtensionWriter, override what you need, and provide an instance of it for your GpxWriterSettings.ExtensionWriter. The namespaces of your XElement instances should get written out correctly if necessary, though I think it will wind up writing out the same xmlns:foo declaration on every single place where it's used, and I'm not 100% sure off the top of my head if it's going to pick the namespace prefix you want it to.

lorenh commented 5 years ago

OK, that's what I thought. Technically speaking the XML namespace declaration should be interpreted by the XML parser the same whether it's at the top or duplicated on each element. I was just trying to match a spec given to me. Now I know I can't do it quite the way they want. Hopefully this will be sufficient. But keep it in mind if you are ever in there tinkering with this area in case some way to customize things like this pops into your head.

airbreather commented 5 years ago

I wouldn't mind adding the option to accept a list of namespace / prefix pairs in GpxWriterSettings, if for no other reason than to shrink the output for these cases.

lorenh commented 5 years ago

OK, I guess I'd like that feature added when you get around to it.

lorenh commented 5 years ago

I created a pull request with one way you could achieve this, I'm sure you can improve on it.

https://github.com/NetTopologySuite/NetTopologySuite.IO.GPX/pull/37

lorenh commented 5 years ago

Still curious if this is on a roadmap for a future release? I'd love to abandon using the custom package I built.

airbreather commented 5 years ago

Yes -- I'm focusing most of my free time on the NTS v2 upgrades, so this is going to be a while.

lorenh commented 5 years ago

I updated the PR for this to merge cleanly into 1.0 branch in case you ever get around to it. Again, I'd love to abandon using my custom package.

airbreather commented 4 years ago

Resolved by #37, but I'm going to see if I can make it any better before releasing a 1.1.0 that includes it.

airbreather commented 4 years ago

1.1.0 is on NuGet with the most important fix for this. I'll open a new issue to track parsing out existing namespaces on read for the sake of a better round-trip.