Пример #1
0
        /// <summary>
        /// Parses the stream and returns the result.
        /// </summary>
        public IHtmlDocument Parse(Stream source)
        {
            var document = CreateDocument(source);
            var parser   = new HtmlDomBuilder(document);

            return(parser.Parse(_options));
        }
Пример #2
0
        /// <summary>
        /// Parses the string and returns the result.
        /// </summary>
        public IHtmlDocument Parse(String source)
        {
            var document = CreateDocument(source);

            using (var parser = new HtmlDomBuilder(document))
            {
                return(parser.Parse(_options));
            }
        }
Пример #3
0
        private INodeList ParseFragment(HtmlDocument document, IElement contextElement)
        {
            var parser = new HtmlDomBuilder(document);

            if (contextElement is Element element)
            {
                element = document.CreateElementFrom(element.LocalName, element.Prefix);
                var fragment = parser.ParseFragment(_options, element).DocumentElement;
                element.AppendNodes(fragment.ChildNodes.ToArray());
                return(element.ChildNodes);
            }

            return(parser.Parse(_options).ChildNodes);
        }
Пример #4
0
        /// <summary>
        /// Parses the string and returns the result.
        /// </summary>
        public INodeList ParseFragment(String source, IElement context)
        {
            var document = CreateDocument(source);
            var parser   = new HtmlDomBuilder(document);

            if (context != null)
            {
                var element = context as Element ??
                              Factory.HtmlElements.Create(document, context.LocalName, context.Prefix);
                return(parser.ParseFragment(_options, element).DocumentElement.ChildNodes);
            }

            return(parser.Parse(_options).ChildNodes);
        }
Пример #5
0
        /// <summary>
        /// Parses the string and returns the result.
        /// </summary>
        public INodeList ParseFragment(String source, IElement contextElement)
        {
            var document = CreateDocument(source);
            var parser   = new HtmlDomBuilder(document);
            var element  = contextElement as Element;

            if (element != null)
            {
                var context = document.Context;
                element = document.CreateElementFrom(contextElement.LocalName, contextElement.Prefix);
                return(parser.ParseFragment(_options, element).DocumentElement.ChildNodes);
            }

            return(parser.Parse(_options).ChildNodes);
        }
Пример #6
0
        /// <summary>
        /// Parses the string and returns the result.
        /// </summary>
        public INodeList ParseFragment(String source, IElement contextElement)
        {
            var document = CreateDocument(source);
            var parser   = new HtmlDomBuilder(document);

            if (contextElement is Element element)
            {
                var context = document.Context;
                element = document.CreateElementFrom(contextElement.LocalName, contextElement.Prefix);
                var fragment = parser.ParseFragment(_options, element).DocumentElement;
                element.AppendNodes(fragment.ChildNodes.ToArray());
                return(element.ChildNodes);
            }

            return(parser.Parse(_options).ChildNodes);
        }
Пример #7
0
        /// <summary>
        /// Parses the string and returns the result.
        /// </summary>
        public INodeList ParseFragment(String source, IElement context)
        {
            var document = CreateDocument(source);
            var parser   = new HtmlDomBuilder(document);

            if (context != null)
            {
                var element = context as Element;

                if (element == null)
                {
                    var configuration = document.Options;
                    var factory       = configuration.GetFactory <IHtmlElementFactory>();
                    element = factory.Create(document, context.LocalName, context.Prefix);
                }

                return(parser.ParseFragment(_options, element).DocumentElement.ChildNodes);
            }

            return(parser.Parse(_options).ChildNodes);
        }