Subscribe to
Posts
Comments

Archive for the 'Open Sitemap Generator' Category


If you need to escape a string to use in a xml file (or stream), you have to escape those entities:

CharacterEscape Code
Ampersand &  &
Single Quote   '
Double Quote   "
Greater Than >  >
Less Than <  &lt;

To achieve this result you could use the SecurityElement.Escape(string str) C# function, but it has a problem.
If your string has some entities already escaped, it escapes them again.
It happens to us testing our sitemaps generator when it finds URLs on a page that are already escaped.
So we’ve developed this function that tests every & character before to escape it.

public string EscapeXmlString(string URL)
{
//Avoid errors if the string is already escaped for xml use
    for (int i = 0; i < URL.Length-1; i++)
    {
        if (URL[i] == ‘&’)
        {
            switch (URL[i + 1])
            {
                case ‘a’:
                    if ((i + 5 < URL.Length) && (URL.Substring(i, 6) == “&apos;”))
                    {
                        continue;
                    }
                    else
                    {
                        if ((i + 4 < URL.Length) && (URL.Substring(i, 5) == “&amp;”))
                        {
                            continue;
                        }
                        else
                        {
                            //Escape it
                            URL = URL.Insert(i+1, “amp;”);
                        }
                    }
                break;
                case ‘q’:
                    if ((i + 5 < URL.Length) && (URL.Substring(i, 6) == “&quot;”))
                    {
                        continue;
                    }
                    else
                    {
                        //Escape it
                        URL = URL.Insert(i+1, “amp;”);
                    }
                break;
                case ‘g’:
                    if ((i + 3 < URL.Length) && (URL.Substring(i, 4) == “&gt;”))
                    {
                        continue;
                    }
                    else
                    {
                        //Escape it
                        URL = URL.Insert(i+1, “amp;”);
                    }
                break;
                case ‘l’:
                    if ((i + 3 < URL.Length) && (URL.Substring(i, 4) == “&lt;”))
                    {
                        continue;
                    }
                    else
                    {
                        //Escape it
                        URL = URL.Insert(i+1, “amp;”);
                    }
                break;
                default://Escape it
                    URL = URL.Insert(i+1, “amp;”);
                    break;
            }
        }
    }
 
    URL = URL.Replace(“‘”, “&apos;”);
    URL = URL.Replace(\”, “&quot;”);
    URL = URL.Replace(“>”, “&gt;”);
    URL = URL.Replace(“<”, “&lt;”);
 
    return URL;
}


Mike

We’re proud to announce that Open Sitemap Generator 0.5 “Let-it-Be” has been released.
We regularly use this software to generate the sitemaps of our sites, but this is still a beta release only because we need a bigger users base to test it.
So try it and give us your feedback!

You can download this version from here.
Mike

We’ve opened a Google Groups (beta) group to use as support forum for our Open Sitemap Generator.
You can find it here: http://groups-beta.google.com/group/open-sitemap-generator/topics/

Mike
The gzipping feature of our Open Sitemap Generator is provided by the good SharpLibZip library.

To use it, you need to include reference to ICSharpCode.SharpZipLib.dll and then add this using clause:
using ICSharpCode.SharpZipLib.GZip;


Then, given that filepath is a string containing a valid path for the to-be-gzipped file, this snippet will gzip it to a new file, without loading it all in memory (that’s good for big files).
Stream s = new GZipOutputStream(File.Create(filepath + “.gz”));
FileStream fs = File.OpenRead(filepath);
int size;
byte[] data = new byte[2048];
do
{
    size = fs.Read(data, 0, data.Length);
    s.Write(data, 0, size);
} while (size > 0);
s.Close();
fs.Close();

Given that filepath is C:\mypath\mygoodfile.ext it will create the gzipped version in C:\mypath\mygoodfile.ext.gz.

Mike

Let’s go opensource

We were unhappy with the existing sitemaps softwares, so we’ve started our opensource project.
The goal is to develop a fast and lightweight sitemaps generator.
At the moment we’ve opened the project at SourceForge, at this URL: https://sourceforge.net/projects/sitemapgen.

The software is in an early alpha stage, at the moment you can only download a first ugly alpha version sourcecode from the subversion repository.
We’re are also working on a page in this blog.

You can read all the news in this blog, in the “Sitemap Generator” category.

Mike