Ejemplo n.º 1
0
        /// <summary>
        /// 解析 html
        /// 返回文档
        /// </summary>
        /// <param name="content">要解析的 html</param>
        /// <returns>DOM 文档</returns>
        public static Document Parse(string content)
        {
            //创建标签阅读器
            ReaderBase reader = new TagReader();

            //阅读器上下文
            Context context = new Context(content, c => HtmlParser.Parse(c));

            //设置上下文
            reader.Context = context;

            //读取所有内容
            while (true)
            {
                //执行读取 返回下一个阅读器
                reader = reader.Read();

                //不返回阅读器 读取完毕 跳出
                if (reader.IsNull())
                {
                    break;
                }
            }

            //返回文档元素
            return(context.Document);
        }