Done. I have a working GPX Waypoint cleanup tool.
Quick-n-dirty, here's the core part of my code ( I'm using .net file and string functions ).
(I'm not a programmer, so go easy on my laughable code!)
If anyone wants a copy of either the final program, or the entire Visual Studio project, drop me a PM.
ETA: This tool is doing *exactly* what I wanted, and I'm really happy with it.
It reads in a GPX file, and passes it through un-changed, except WPT elements, which are parsed through and I only output the lines I want.
The Lat/Long are in the opening tags of the WPT in my example source GPX, so I'm not searching for those explicitly; they get included in the opening tag.
The only other tag I'm preserving is the name.
I've added the option to preserve timedate stamps, and elevations.
It is coded to work with my mapsource exports, and may barf with other GPX files which do their XML differently. I'm not attempting to parse the XML; I'm just doing line-by-line text editor stuff.
using (StreamReader Input = new StreamReader(InFileName))
{
using (StreamWriter Output = new StreamWriter(OutFileName))
{
//Read input file line by line
while ((CurrentLine = Input.ReadLine()) != null)
{
//Is this line the opening tag of a wpt?
if (CurrentLine.Trim().StartsWith("<wpt"))
{
//yes, so process the wpt up to it's closing tag.
WPT_count++;
//We already have the opening tag ,so write it out.
Output.WriteLine(CurrentLine);
//now continue reading lines till we find the closing tag
do
{
CurrentLine = Input.ReadLine();
//Write out only the Chosen Ones...
//Output.WriteLine(CurrentLine);
if (CurrentLine.Trim().StartsWith("<name")) Output.WriteLine(CurrentLine);
if (CurrentLine.Trim().StartsWith("<ele") && (checkBox2.Checked == true)) Output.WriteLine(CurrentLine);
if (CurrentLine.Trim().StartsWith("<time") && (checkBox1.Checked == true)) Output.WriteLine(CurrentLine);
//All other attributes in the wpt are ignored.
}
while (!(CurrentLine.Trim().StartsWith("</wpt")));
//we just exited the loop because we just read the closing tag. We must now write it out too.
Output.WriteLine(CurrentLine);
}
else
{
//no, it's not, eg header info so just copy it out.
Output.WriteLine(CurrentLine);
}
}
}
}