Example #1
0
        static IEnumerable<WikiPage> ReadNextPage(string inputFile)
        {
            WikiPage page = new WikiPage();
            var skipCurrentPage = true;

            using (XmlReader reader = XmlReader.Create(inputFile))
            {
                reader.MoveToContent();
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (skipCurrentPage && reader.Name != "page")
                        {
                            continue;
                        }

                        switch (reader.Name)
                        {
                            case "page":
                                if (!skipCurrentPage)
                                {
                                    yield return page;
                                }
                                page = new WikiPage();
                                skipCurrentPage = false;
                                break;
                            case "ns":
                                if (reader.ReadElementContentAsString() != "0")
                                {
                                    skipCurrentPage = true;
                                }
                                break;
                            case "title":
                                page.Title = reader.ReadElementContentAsString();
                                break;
                            case "text":
                                page.Text = reader.ReadElementContentAsString();
                                break;
                        }
                    }
                }
            }

            yield break;
        }