473,394 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C#-APP: Reading Garmin GPX File

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 6760

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

Similar topics

20
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....
30
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
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...
12
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: ...
11
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...
8
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....
4
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...
7
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...
2
by: Srinivas3279 | last post by:
I am new to the C/C++ My Program: int main(int argc, _TCHAR* argv) { //Declarations FILE *fp;
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.