S
Stuart Shay
Hello All:
I am trying to create a GPX File from my domain objects I am able to create
the file, but I can properly assign the default namespace to the xml
In the Code Below I trying to define the namespace as follows
<gpx version="1.1" creator="Garmin Connect"
xmlns="http://www.topografix.com/GPX/1/1"
How Do I Define a NS with out a prefix. I added a attribute to the Root but
then the Children got the namespace appended to all the Tags
Thanks
Stuart
/* Source Code */
XNamespace ns = "http://www.topografix.com/GPX/1/1";
XNamespace gpxtpx =
"http://www.garmin.com/xmlschemas/TrackPointExtension/v1";
XNamespace gpxx = "http://www.garmin.com/xmlschemas/GpxExtensions/v3";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace 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://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd
http://www.garmin.com/xmlschemas/TrackPointExtension/v1
http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd";
var xml = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("gpx",
new XAttribute("version", "1.1"),
new XAttribute("creator", "GPS Navigator"),
new XAttribute(xsi + "SchemaLocation",
schemaLocation.ToString()),
/****** Fomat
xmlns="http://www.topografix.com/GPX/1/1" *******/
new XAttribute(XNamespace.Xmlns + "NOPREFIX",
ns),
new XAttribute(XNamespace.Xmlns + "gpxtpx",
gpxtpx),
new XAttribute(XNamespace.Xmlns + "gpxx",
gpxx),
new XAttribute(XNamespace.Xmlns + "xsi", xsi),
new XElement("metadata", new XElement("time")),
from entry in
gpx.Trk.TrkSegments
select new XElement("trk",
new XElement("name",
entry.Name), new XElement("trkseg",
from t in entry.Trkpoints
select new XElement("trkpt",
new XAttribute("lon", t.Lon),new XAttribute("lat", t.Lat),
new XElement("ele", t.Ele)
,new XElement("time", t.Time))
)
)
));
I am trying to create a GPX File from my domain objects I am able to create
the file, but I can properly assign the default namespace to the xml
In the Code Below I trying to define the namespace as follows
<gpx version="1.1" creator="Garmin Connect"
xmlns="http://www.topografix.com/GPX/1/1"
How Do I Define a NS with out a prefix. I added a attribute to the Root but
then the Children got the namespace appended to all the Tags
Thanks
Stuart
/* Source Code */
XNamespace ns = "http://www.topografix.com/GPX/1/1";
XNamespace gpxtpx =
"http://www.garmin.com/xmlschemas/TrackPointExtension/v1";
XNamespace gpxx = "http://www.garmin.com/xmlschemas/GpxExtensions/v3";
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace 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://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd
http://www.garmin.com/xmlschemas/TrackPointExtension/v1
http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd";
var xml = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("gpx",
new XAttribute("version", "1.1"),
new XAttribute("creator", "GPS Navigator"),
new XAttribute(xsi + "SchemaLocation",
schemaLocation.ToString()),
/****** Fomat
xmlns="http://www.topografix.com/GPX/1/1" *******/
new XAttribute(XNamespace.Xmlns + "NOPREFIX",
ns),
new XAttribute(XNamespace.Xmlns + "gpxtpx",
gpxtpx),
new XAttribute(XNamespace.Xmlns + "gpxx",
gpxx),
new XAttribute(XNamespace.Xmlns + "xsi", xsi),
new XElement("metadata", new XElement("time")),
from entry in
gpx.Trk.TrkSegments
select new XElement("trk",
new XElement("name",
entry.Name), new XElement("trkseg",
from t in entry.Trkpoints
select new XElement("trkpt",
new XAttribute("lon", t.Lon),new XAttribute("lat", t.Lat),
new XElement("ele", t.Ele)
,new XElement("time", t.Time))
)
)
));