473,796 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-APP: Reading Garmin GPX File

1 New Member
Hi All

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
  1. <?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
  2. <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">
  3.     <metadata>
  4.         <link href="http://www.garmin.com">
  5.             <text>Garmin International</text> 
  6.         </link>
  7.         <time>2007-08-13T16:22:39Z</time> 
  8.         <bounds maxlat="-26.264876" maxlon="28.141640" minlat="-34.057666" minlon="23.375585" /> 
  9.     </metadata>
  10.     <wpt lat="-26.264876" lon="28.141640">
  11.         <time>2007-07-31T09:53:54Z</time> 
  12.         <name>FC149 40km M94E</name> 
  13.         <cmt>M94 Kritzinger Rd eastwards 40kph</cmt> 
  14.         <desc>M94 Kritzinger Rd eastwards 40kph</desc> 
  15.         <sym>Scenic Area</sym> 
  16.         <extensions>
  17.             <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">
  18.             <gpxx:Proximity>250.000000</gpxx:Proximity> 
  19.             <gpxx:DisplayMode>SymbolAndName</gpxx:DisplayMode> 
  20.             </gpxx:WaypointExtension>
  21.         </extensions>
  22.     </wpt>
  23.     <wpt lat="-34.057666" lon="23.375585">
  24.         <time>2007-05-18T18:02:29Z</time> 
  25.         <name>FC355 40km Strand Str</name> 
  26.         <cmt>Strand Str Plettenburg Bay 40kph (yes! 40)</cmt> 
  27.         <desc>Strand Str Plettenburg Bay 40kph (yes! 40)</desc> 
  28.         <sym>Scenic Area</sym> 
  29.         <extensions>
  30.             <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">
  31.             <gpxx:Proximity>250.000000</gpxx:Proximity> 
  32.             <gpxx:DisplayMode>SymbolAndName</gpxx:DisplayMode> 
  33.             </gpxx:WaypointExtension>
  34.         </extensions>
  35.     </wpt>
  36. </gpx>
  37.  
The C# Code
Expand|Select|Wrap|Line Numbers
  1.         private bool AddGPXFile(FileInfo File)
  2.         {
  3.             Node[] pNode; int N;
  4.             int I; int X; int Y; int Q;
  5.             string Last;
  6.             TreeNode TN;
  7.             string Header; string Footer; string MetaData;
  8.             string Contents;
  9.             XmlDocument XD = new XmlDocument();
  10.             XD.Load(File.FullName);
  11.             for (I = 0; I < XD.ChildNodes.Count ; I++){
  12.                 //MessageBox.Show(XD.ChildNodes.Item(I).Name);
  13.                 if (XD.ChildNodes.Item(I).Name.ToUpper() == "GPX")
  14.                 {
  15.                     for (X = 0; X < XD.ChildNodes.Item(I).ChildNodes.Count; X++)
  16.                     {
  17.                         if (XD.ChildNodes.Item(I).ChildNodes.Item(X).Name.ToUpper() == "WPT")
  18.                         {
  19.                             for (Y = 0; Y < XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Count; Y++) 
  20.                             {
  21.                                 //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);
  22.                                 Last = XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).Name + " - " + XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Count;
  23.                                 if (Last.ToUpper().StartsWith("EXTENSION"))
  24.                                 {
  25.                                     for (Q = 0; Q < XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Count; Q++)
  26.                                     {
  27.                                         MessageBox.Show(XD.ChildNodes.Item(I).ChildNodes.Item(X).ChildNodes.Item(Y).ChildNodes.Item(Q).OuterXml);
  28.                                         //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());
  29.                                     }
  30.                                 }
  31.                             }
  32.                         }
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             TN = this.trvFiles.Nodes.Add(File.Name);
  38.             TN.Tag = XD;
  39.             TN.Nodes.Add("Original: ");
  40.             TN.Nodes.Add("Added: ");
  41.             TN.Expand();
  42.             return true;
  43.         }
  44.  
I know for a fact that this cannot be the best way for reading an XML file, so if someone would point me in the right direction (excuse the pun), it would be greatly appreciated.

Thanx
Aug 16 '07 #1
0 6833

Sign in to post your reply or Sign up for a free account.

Similar topics

20
33079
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2. From here read a character, print it, move the file pointer (FILE*) to 2 steps back (using fseek(fp, -2, SEEK_CUR)) to read the previous character. This seems to be ok if the file has a single line (i.e. no new line character). The above logic...
30
4594
by: siliconwafer | last post by:
Hi All, I want to know tht how can one Stop reading a file in C (e.g a Hex file)with no 'EOF'?
21
6397
by: EdUarDo | last post by:
Hi all, I'm not a newbie with C, but I don't use it since more than 5 years... I'm trying to read a text file which has doubles in it: 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 2.4 I'm doing this (it's only a test trying to achieve the goal...):
12
1921
by: mitek777 | last post by:
Hi, I have a problem with reading from file. I would like to find some string(f e.g. name) in file, and if it exist show it on screen with second and third line under. I have this in file: name surname age
11
3597
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function Read_bin(ByVal ruta As String) Dim cadena As String = "" Dim dato As Array If File.Exists(ruta) = True Then
8
3228
by: Lonifasiko | last post by:
Hi, Using Process class I asynchronously launch an executable (black box executable) file from my Windows application. I mean asynchronously because I've got an EventHandler for "Exited" event. Therefore, when process finishes, "Exited" event is raised. This executable writes a long file for over 1-5 minutes, and I, from my application must read that file while is being generated.
4
11111
by: archana | last post by:
Hi all, I want to read csv file into datatable. Is there any csv reader and writer available for freeware. I am reading csv file using schema.ini file. I don't want this dependency. The problem while reading csv is that datatype depend on first 8 or 16 rows depend in value set in registry. Is there any option provided in framework 2.0 to read content of csv
7
4570
by: tackleberi | last post by:
hi, im having some trouble reading a file into java and then storing it in an array here the code i have so far: import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; import javax.swing.JOptionPane; public class samplecode {
2
2435
by: Srinivas3279 | last post by:
I am new to the C/C++ My Program: int main(int argc, _TCHAR* argv) { //Declarations FILE *fp;
2
1721
by: electromania | last post by:
Hi, Im reading a file, with 2 columns. this is working as Im reading I want to be able to count how many rows I've read and also add the all values as im reading from the second column, could some help plz This is the code #include <stdio.h> #include <stdlib.h>
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10187
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.