+imajeep Posted November 10, 2007 Posted November 10, 2007 (edited) I am writing some code in .NET to create a GPX file, and I need a little bit of help coding the document node of a GPX file. I am using the XmlDocument class and its related classes. I'm having trouble declaring the 'xmlns:xsi' and 'xsi:schemaLocation' attributes of the document (<gpx>) node. I can declare the XSI namespace, using the XmlDocument.CreateAttribute() method, but .NET ignores the prefix in the 'xsi:schemaLocation' attribute. All that gets written is 'schemaLocation', which causes the document to be invalid. Does anyone have a snippet that shows how to code a GPX document node in either VB.NET or C#? Thanks for your help! David Veeneman Foresight Systems a/k/a 'imajeep' Edited November 10, 2007 by imajeep Quote
+imajeep Posted November 10, 2007 Author Posted November 10, 2007 I got an answer at A href="n"tp://microsoft.public.dotnet.xml">nntp://microsoft.public.dotnet.xml. The short answer is that namespace declarations aren't done explicitly. Instead, they are set by calling the SetAttribute() overload that takes a prefix and a namespace URI. Here is the code to create the root node: const string gpx = "http://www.topografix.com/GPX/1/1", xsi = "http://www.w3.org/2001/XMLSchema-instance"; XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("gpx", gpx); root.SetAttribute("version", "1.1"); root.SetAttribute("creator", "ExpertGPS 2.4.2"); XmlAttribute schemaLocation = xmlDoc.CreateAttribute("xsi", "schemaLocation", xsi); schemaLocation.Value = @"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/gpx_style/0/2 http://www.topografix.com/GPX/gpx_style/0/2/gpx_style.xsd http://www.topografix.com/GPX/gpx_overlay/0/3 http://www.topografix.com/GPX/gpx_overlay/...gpx_overlay.xsd http://www.topografix.com/GPX/gpx_modified/0/1 http://www.topografix.com/GPX/gpx_modified...px_modified.xsd"; root.SetAttributeNode(schemaLocation); xmlDoc.AppendChild(root); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.