Exemple #1
0
        /// <summary>
        /// Loads the html page.
        /// </summary>
        /// <param name="p"></param>
        public void ReadHtml(string url)
        {
            FileInfo info = new FileInfo(url);
            FileHandler fh = new FileHandler(info.Extension);
            fh.LoadFile(info);
            contents = fh.GetFileFromMemory(info);
            IEnumerator<string> iter = contents.GetEnumerator();

            using (XmlTextReader reader = new XmlTextReader(url))
            {
                reader.DtdProcessing = DtdProcessing.Ignore;
                reader.WhitespaceHandling = WhitespaceHandling.None;

                reader.MoveToContent();
                while (reader.Read())
                {
                    reader.MoveToContent();
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        Console.Write("<" + reader.LocalName);
                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                Console.Write(@" {0}=""{1}""", reader.Name, reader.Value);

                                //Console.WriteLine("Name:{0} Type:{1} Value:{2}", reader.Name, reader.NodeType, reader.Value);
                            }
                            reader.MoveToElement();
                        }
                        if (reader.IsEmptyElement)
                        {
                            Console.Write(" /");
                        }
                        Console.WriteLine(">");
                    }
                    if (reader.HasValue)
                        Console.WriteLine(reader.Value);
                    if (reader.NodeType == XmlNodeType.EndElement)
                        Console.WriteLine("</" + reader.LocalName + ">");

                    //Console.WriteLine(reader.NodeType + " " + ((reader.NodeType == XmlNodeType.Text) ? ("= " + reader.Value) : ": "+reader.LocalName));
                }
            }
            HtmlNode<string> node = null;
            using (XmlTextReader reader = new XmlTextReader(url))
            {
                reader.DtdProcessing = DtdProcessing.Ignore;
                reader.WhitespaceHandling = WhitespaceHandling.None;

                reader.MoveToContent();
                XmlReader subTree = reader.ReadSubtree();
                node = ParseXML(subTree);
            }
            Console.WriteLine(node);
        }