Advertisement
Guest User

SiteMapReader

a guest
May 13th, 2013
8,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8. using System.Data;
  9. using System.Xml;
  10. namespace SiteMapReader
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.WriteLine("Please Enter the Location of the file");
  17.             // get the location we want to get the sitemaps from
  18.             string dirLoc = Console.ReadLine();
  19.             // get all teh sitemaps
  20.             string[] sitemaps = Directory.GetFiles(dirLoc);
  21.             StreamWriter sw = new StreamWriter(Application.StartupPath + @"\locs.txt", true);
  22.  
  23.             // loop through each file
  24.             foreach (string sitemap in sitemaps)
  25.             {
  26.                 try
  27.                 {
  28.                     // new xdoc instance
  29.                     XmlDocument xDoc = new XmlDocument();
  30.                     //load up the xml from the location
  31.                     xDoc.Load(sitemap);
  32.                     // cycle through each child noed
  33.                     foreach (XmlNode node in xDoc.DocumentElement.ChildNodes)
  34.                     {
  35.                         // first node is the url ... have to go to nexted loc node
  36.                         foreach (XmlNode locNode in node)
  37.                         {
  38.                             // thereare a couple child nodes here so only take data from node named loc
  39.                             if (locNode.Name == "loc")
  40.                             {
  41.                                 // get the content of the loc node
  42.                                 string loc = locNode.InnerText;
  43.                                 // write it to the console so you can see its working
  44.                                 Console.WriteLine(loc + Environment.NewLine);
  45.                                 // write it to the file
  46.                                 sw.Write(loc + Environment.NewLine);
  47.  
  48.                             }
  49.                         }
  50.                     }
  51.                 }
  52.                 catch { }
  53.             }
  54.             Console.WriteLine("All Done :-)");
  55.             Console.ReadLine();
  56.         }
  57.  
  58.         static void readSitemap()
  59.         {
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement