Beispiel #1
0
        private static void ParseElement(XmlElement element, Chapter chapter)
        {
            foreach (var child in element.ChildNodes)
            {
                if (child is Windows.Data.Xml.Dom.XmlText)
                {
                    if (string.IsNullOrEmpty(child.InnerText) ||
                        child.InnerText == "\n")
                    {
                        continue;
                    }

                    // Add a verse?

                    //parent.Add(new Run { Text = ((XmlText)child).InnerText });
                }
                else if (child is XmlElement)
                {
                    XmlElement e = (XmlElement)child;
                    switch (e.TagName.ToUpper())
                    {
                        case "DIV":
                            if (e.GetAttribute("class") == "p")
                            {
                                // Start of a new paragraph
                                chapter.Sections.Add(new Section());
                                ParseElement(e, chapter);

                            }
                            else if (e.GetAttribute("class") == "label" && element.GetAttribute("class").Contains("chapter"))
                            {
                                // Set chapter name
                                chapter.BookName = e.InnerText;

                            }
                            else
                            {
                                ParseElement(e, chapter);
                            }
                            break;
                        case "SPAN":
                            //ParseElement(e, parent);

                            if (e.GetAttribute("class") == "heading")
                            {
                                chapter.Sections.Add(new Section(e.InnerText));
                            }
                            else if (e.GetAttribute("class") == "label" && element.GetAttribute("class").Contains("verse"))
                            {
                                Verse verse = new Verse();
                                verse.Number = int.Parse(e.InnerText);
                                chapter.Verses.Add(verse);
                                chapter.Sections.Last().Verses.Add(verse);
                            }
                            else if (e.GetAttribute("class") == "content" && element.GetAttribute("class").Contains("verse"))
                            {
                                if (chapter.Verses.Last().Text == null)
                                {
                                    chapter.Verses.Last().Text = e.InnerText;
                                }
                            }
                            else
                            {
                                ParseElement(e, chapter);
                            }
                            //else
                            //{
                            //    Run run = new Run();
                            //    run.Text = e.InnerText;
                            //    parent.Add(run);
                            //}
                            break;
                        //case "P":
                        //    var p = new Paragraph();
                        //    parent.Add(p);
                        //    ParseElement(e, new ParagraphTextContainer(p));
                        //    break;
                        //case "STRONG":
                        //    var bold = new Bold();
                        //    parent.Add(bold);
                        //    ParseElement(e, new SpanTextContainer(bold));
                        //    break;
                        //case "U":
                        //    var underline = new Underline();
                        //    parent.Add(underline);
                        //    ParseElement(e, new SpanTextContainer(underline));
                        //    break;
                        //case "A":
                        //    ParseElement(e, parent);
                        //    break;
                        //case "BR":
                        //    parent.Add(new LineBreak());
                        //    break;
                    }
                }


            }
        }
Beispiel #2
0
 private static void ParseElement(XmlElement element, Chapter chapter, Style currentTextStyle)
 {
     foreach (var child in element.ChildNodes)
     {
         if (child is Windows.Data.Xml.Dom.XmlText)
         {
             if (string.IsNullOrEmpty(child.InnerText) ||
                 child.InnerText == "\n")
             {
                 continue;
             }
         }
         else if (child is XmlElement)
         {
             XmlElement e = (XmlElement)child;
             switch (e.TagName.ToUpper())
             {
                 case "DIV":
                     if (e.GetAttribute("class") == "p")
                     {
                         // Start of a new paragraph
                         chapter.Sections.Add(new Section());
                         ParseElement(e, chapter, currentTextStyle);
                     }
                     if (e.GetAttribute("class") == "s1")
                     {
                         // New heading section
                         chapter.Sections.Add(new Section());
                         ParseElement(e, chapter, currentTextStyle);
                     }
                     else
                     {
                         ParseElement(e, chapter, currentTextStyle);
                     }
                     break;
                 case "SPAN":
                     if (e.GetAttribute("class") == "heading" && element.GetAttribute("class").Contains("s1")) //(e.GetAttribute("class") == "heading")
                     {
                         chapter.Sections.Last().Heading.Add(new TextSpan(e.InnerText, currentTextStyle));
                     }
                     else if (e.GetAttribute("class") == "label" && element.GetAttribute("class").Contains("verse"))
                     {
                         Verse verse = new Verse();
                         verse.Number = int.Parse(e.InnerText);
                         chapter.Verses.Add(verse);
                         if (chapter.Sections.Count == 0)
                         {
                             chapter.Sections.Add(new Section());
                         }
                         chapter.Sections.Last().Verses.Add(verse);
                     }
                     else if (e.GetAttribute("class") == "content" && element.GetAttribute("class").Contains("verse"))
                     {
                         chapter.Verses.Last().TextSpans.Add(new TextSpan(e.InnerText, currentTextStyle));
                     }
                     else if (e.GetAttribute("class") == "content" && element.GetAttribute("class").Contains("nd"))
                     {
                         chapter.Verses.Last().TextSpans.Add(new TextSpan(e.InnerText, Style.NAME_OF_GOD));
                     }
                     else if (e.GetAttribute("class") == "heading" && element.GetAttribute("class").Contains("nd"))
                     {
                         //chapter.Sections.Last().Heading.Add(new TextSpan(e.InnerText, Style.NAME_OF_GOD));
                     }
                     else if (element.GetAttribute("class") == "q1" && e.GetAttribute("class").Contains("verse"))
                     {
                         ParseElement(e, chapter, Style.QUOTE1);
                     }
                     else if (element.GetAttribute("class") == "q2" && e.GetAttribute("class").Contains("verse"))
                     {
                         ParseElement(e, chapter, Style.QUOTE2);
                     }
                     else if (e.GetAttribute("class") == "wj" && element.GetAttribute("class").Contains("verse"))
                     {
                         chapter.Verses.Last().TextSpans.Add(new TextSpan(e.InnerText, Style.WORDS_OF_JESUS));
                     }
                     else
                     {
                         ParseElement(e, chapter, currentTextStyle);
                     }
                     break;
             }
         }
     }
 }