Firstly: I have searched everywhere! I couldn't find anything!
Secondly: I am VERY new (1 and a half days) to C#, but I have been doing VB6 and VB.Net for years now. I want to learn C# !
Now that I have that out of the way...
I want to write an application that will open multiple Garmin GPX files and display them in a tree view (The filename being the Text, with 2 sub-nodes), so that I can drag waypoints from one file to another.
The problem is that I have no idea how to read the GPX (XML Format) in such a way that I will be able to save the files again, with the dragged waypoints in the new files.
Below I have a small sample of the GPX file, as well as the code that I currently use.
The GPX File
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <gpx xmlns="http://www.topografix.com/GPX/1/1" creator="MapSource 6.11.6" version="1.1" 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">
- <metadata>
- <link href="http://www.garmin.com">
- <text>Garmin International</text>
- </link>
- <time>2007-08-13T16:22:39Z</time>
- <bounds maxlat="-26.264876" maxlon="28.141640" minlat="-34.057666" minlon="23.375585" />
- </metadata>
- <wpt lat="-26.264876" lon="28.141640">
- <time>2007-07-31T09:53:54Z</time>
- <name>FC149 40km M94E</name>
- <cmt>M94 Kritzinger Rd eastwards 40kph</cmt>
- <desc>M94 Kritzinger Rd eastwards 40kph</desc>
- <sym>Scenic Area</sym>
- <extensions>
- <gpxx:WaypointExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd">
- <gpxx:Proximity>250.000000</gpxx:Proximity>
- <gpxx:DisplayMode>SymbolAndName</gpxx:DisplayMode>
- </gpxx:WaypointExtension>
- </extensions>
- </wpt>
- <wpt lat="-34.057666" lon="23.375585">
- <time>2007-05-18T18:02:29Z</time>
- <name>FC355 40km Strand Str</name>
- <cmt>Strand Str Plettenburg Bay 40kph (yes! 40)</cmt>
- <desc>Strand Str Plettenburg Bay 40kph (yes! 40)</desc>
- <sym>Scenic Area</sym>
- <extensions>
- <gpxx:WaypointExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd">
- <gpxx:Proximity>250.000000</gpxx:Proximity>
- <gpxx:DisplayMode>SymbolAndName</gpxx:DisplayMode>
- </gpxx:WaypointExtension>
- </extensions>
- </wpt>
- </gpx>
Expand|Select|Wrap|Line Numbers
- private bool AddGPXFile(FileInfo File)
- {
- Node[] pNode; int N;
- int I; int X; int Y; int Q;
- string Last;
- TreeNode TN;
- string Header; string Footer; string MetaData;
- string Contents;
- XmlDocument XD = new XmlDocument();
- XD.Load(File.FullName);
- for (I = 0; I < XD.ChildNodes.Count ; I++){
- //MessageBox.Show(XD.ChildNodes.Item(I).Name);
- if (XD.ChildNodes.Item(I).Name.ToUpper() == "GPX")
- {
- for (X = 0; X < XD.ChildNodes.Item(I).ChildNodes.Count; X++)
- {
- if (XD.ChildNodes.Item(I).ChildNodes.Item(X).Name.ToUpper() == "WPT")
- {
- for (Y = 0; Y < XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Count; Y++)
- {
- //MessageBox.Show(XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).Name + " - " + XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Count);
- Last = XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).Name + " - " + XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Count;
- if (Last.ToUpper().StartsWith("EXTENSION"))
- {
- for (Q = 0; Q < XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Count; Q++)
- {
- MessageBox.Show(XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Item(Q).OuterXml);
- //MessageBox.Show(Last + ": " + XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Item(Q).Name + " :: " + XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Item(Q).NodeType.ToString());
- }
- }
- }
- }
- }
- }
- }
- TN = this.trvFiles.Nodes.Add(File.Name);
- TN.Tag = XD;
- TN.Nodes.Add("Original: ");
- TN.Nodes.Add("Added: ");
- TN.Expand();
- return true;
- }
Thanx