1-) C# RMOS - Sitemap Site Haritası Oluşturma Hazırlama ve Gönderme
Türkçe anlamı “Site Haritası” olan sitemap, başarılı bir SEO kurgusu yapmak isteyen her sitenin olmazsa olmazlarındandır. Sitemap, arama motorlarına bir sitede yer alan tüm URL’lerle ilgili bilgilendirme yapar. Bu sayede arama motorlarının botları söz konusu siteyi ziyaret ettiklerinde daha kolay bilgi alırlar. Bir web sitesinin arama motorlarında üst sıralara çıkması için, mutlaka site haritasına sahip olması gereklidir.
xml i class'a çevirmek için -> http://xmltocsharp.azurewebsites.net/
1-) XmlModel.cs
using System.Collections.Generic;
using System.Xml.Serialization;
namespace RoketnotSiteMap
{
public class XmlModel
{
[XmlRoot(ElementName = "url", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public class Url
{
[XmlElement(ElementName = "loc", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public string Loc { get; set; }
[XmlElement(ElementName = "lastmod", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public string Lastmod { get; set; }
[XmlElement(ElementName = "changefreq", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public string Changefreq { get; set; }
[XmlElement(ElementName = "priority", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public string Priority { get; set; }
}
[XmlRoot(ElementName = "urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public class Urlset
{
[XmlElement(ElementName = "url", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public List<Url> Url { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
}
}
}
2-) obje(class) to xml metot
public static XmlDocument SerializeObjectToXML(object obj, string sElementName)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
XmlDocument xmlDoc = new XmlDocument();
using (MemoryStream ms = new MemoryStream())
{
serializer.Serialize(ms, obj);
ms.Position = 0;
xmlDoc.Load(ms);
}
return xmlDoc;
}
3-) turkce karakter replace metot
public string replaceTurkishKarakter(string text)
{
text = text.Replace("Ş", "S");
text = text.Replace("ş", "s");
text = text.Replace("İ", "I");
text = text.Replace("ı", "i");
text = text.Replace("Ğ", "G");
text = text.Replace("ğ", "g");
text = text.Replace("Ç", "C");
text = text.Replace("ç", "c");
text = text.Replace("Ö", "O");
text = text.Replace("ö", "o");
text = text.Replace("Ü", "U");
text = text.Replace("ü", "u");
return text;
}
4-) Linkleri indirme button click olayı
private void button1_Click(object sender, EventArgs e)
{
hepsi();
}
public void hepsi() {
DataTable dt = dbMySql.MyGetDataTable("SELECT id,not_basligi,not_date FROM tabloAd where not_durum<>0 order by id desc");
Console.WriteLine(dt.Rows.Count);
List<Url> urls = new List<Url>();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
Url urlim = new Url();
string id = dr["id"].ToString();
string not_basligi = dr["not_basligi"].ToString();
string not_date = dr["not_date"].ToString();
not_date = Convert.ToDateTime(not_date).ToString("s") + "Z";
string url = "https://www.roketnot.com/not/";
string not = id + " " + not_basligi;
not = replaceTurkishKarakter(not.ToLower());
url = url + not.Replace(" ", "-").Replace("#", "").Replace(".", "").Replace("=", "");
url = url.Replace("(", "").Replace(")", "");
string changefreq = "monthly";
string priority = "0.5";
urlim.Loc = url;
urlim.Priority = priority;
urlim.Changefreq = changefreq;
urlim.Lastmod = not_date;
urls.Add(urlim);
}
kaydetHespi(urls);
string getPath = AppDomain.CurrentDomain.BaseDirectory;
Process.Start(getPath);
MessageBox.Show("Exenin oldugu yere xml'ler çıktı \n"+ urls.Count + "Adet URL sitemap.xml");
}
public void kaydetHespi(List<Url> urls)
{
Urlset urlset = new Urlset();
urlset.Url = urls;
urlset.Xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";
XmlDocument xmlDocument = SerializeObjectToXML(urlset, "asd");
xmlDocument.InnerXml = xmlDocument.InnerXml.ToString().Replace("version=\"1.0\"", "version=\"1.0\" encoding=\"ISO-8859-9\"");
xmlDocument.InnerXml = xmlDocument.InnerXml.ToString().Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "");
xmlDocument.InnerXml = xmlDocument.InnerXml.ToString().Replace("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", "");
xmlDocument.Save(urls.Count + " Adet URL sitemap.xml");
}
5-) OLUŞAN sitemap.xml
<?xml version="1.0" encoding="ISO-8859-9"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.roketnot.com/not/1457-sitemap-site-haritasi-olusturma-hazirlama-ve-gonderme</loc>
<lastmod>2022-03-26T15:14:00Z</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://www.roketnot.com/not/1454-counter-arttirmak-eksiltmek-increase-decrease-widget-kullanimi</loc>
<lastmod>2022-03-20T15:31:46Z</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://www.roketnot.com/not/1453-tabbarview-tabview-defaulttabcontroller-widget-kullanimi</loc>
<lastmod>2022-03-20T14:23:45Z</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
</urlset>
7-) roketnotumuzun xml'i örnek bakınız. Her yeni url eklendiğinden buradaki xml'i otomatik güncellerseniz güzel olur. Max 50 bin url . max 10MB dosya boyutu
https://www.roketnot.com/sitemap.xml
8-) Google search consoleye eklemek( ayrıca yaho,bing vs arama motorlarınada ekleyebilirsiniz)
*** AYRICA***
1-) Xml i Clasa çevirmek için dinamik istersen
public T loadXml<T>(string path)
{
using (var stream = new FileStream(path, FileMode.Open))
{
var XML = new XmlSerializer(typeof(T));
return (T)XML.Deserialize(stream);
}
}
kullanımı ise
Urlset model = loadXml<Urlset>(xmlPath);
2-) İNTERNETTEN Xml i indirip clasa aktarmak için
string xml;
using (var client = new WebClient())
{
xml = client.DownloadString("https://www.roketnot.com/sitemap.xml");
}
string xmlAd = "sitemap.xml";
File.WriteAllText(xmlAd, xml);
Urlset model = loadXml<Urlset>(xmlAd);