I am trying to create an XML doc according to the following:
https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_ReadersWriters/gpxx/Feature_Types.htm
Just about everything works. However, I am having a problem in the root tag. I want a default namespace. However, it puts in a local name. I have tried various solutions, e.g. empty string, to no avail.
XNamespace def = @"http://www.topografix.com/GPX/1/1";
XNamespace gpxx = @"http://www.garmin.com/xmlschemas/GpxExtensions/v3";
XNamespace xsi = @"http://www.w3.org/2001/XMLSchema-instance";
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "no"),
new XElement("gpx",
new XAttribute(XNamespace.Xmlns + "def", def),
new XAttribute(XNamespace.Xmlns + "gpxx", gpxx),
new XAttribute(XNamespace.Xmlns + "xsi", xsi),
new XAttribute (xsi + "schemalocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd"),
new XElement("metadata",
new XElement("time", DateTime.Now.ToUniversalTime().ToString())
)));
I get:
<gpx xmlns:def="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" 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 http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd">
<metadata>
<time>2019-05-03 18:46:27</time>
</metadata>
What I want is:
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" 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 http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd">
<metadata>
<time>2019-05-03 18:46:27</time>
</metadata>