public static Bible Run() { Bible bible = new Bible("English"); XDocument doc = XDocument.Load("ESV.xml"); var bookElements = doc.Root.Elements("b"); for (int i = 1; i < bookElements.Count() + 1; i++) { var bookElement = bookElements.ElementAt(i - 1); string bookName = bookElement.Attribute("n").Value; Book book = new Book(i, bookName); bible.Books.Add(book); foreach (var chapterElement in bookElement.Elements("c")) { int chapterId = Int32.Parse(chapterElement.Attribute("n").Value); Chapter chapter = new Chapter(chapterId); book.Chapters.Add(chapter); foreach (var verseElement in chapterElement.Elements("v")) { int verseId = Int32.Parse(verseElement.Attribute("n").Value); string text = verseElement.Value; Verse verse = new Verse(verseId, text); chapter.Verses.Add(verse); } } } return bible; }
public static Bible Run() { Bible bible = new Bible("മലയാളം"); Regex regex = new Regex(@"{{verse\|(\d+)}}\s(.*)"); foreach (var pair in _books) { int bookId = pair.Key; string name = pair.Value; int numberOfChapters = Book.ChaptersPerBook[bookId]; Book book = new Book(bookId, name); bible.Books.Add(book); Log.Info("Book " + bookId); for (int i = 1; i < numberOfChapters + 1; i++) { Log.Info(string.Format("Chapter {0}/{1}", i, numberOfChapters)); Chapter chapter = new Chapter(i); book.Chapters.Add(chapter); string url = string.Format("http://malayalambible.in/wiki/{0}:{1}.htm", bookId, i); string page = Web.GetPage(url); string[] lines = page.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < lines.Length; j++) { string line = lines[j]; Match match = regex.Match(line); if (match.Success) { int verseId = Int32.Parse(match.Groups[1].Value); string text = match.Groups[2].Value.Trim(); Verse verse = new Verse(verseId, text); chapter.Verses.Add(verse); } } } } return bible; }