internal DocumentFragment(Element context, String html)
            : this(context.Owner)
        {
            var source   = new TextSource(html);
            var document = new HtmlDocument(Owner.Context, source);
            var parser   = new HtmlDomBuilder(document);
            var options  = new HtmlParserOptions
            {
                IsEmbedded   = false,
                IsStrictMode = false,
                IsScripting  = Owner.Options.IsScripting()
            };
            var root = parser.ParseFragment(options, context).DocumentElement;

            while (root.HasChildNodes)
            {
                var child = root.FirstChild;
                root.RemoveChild(child);
                if (child is Node)
                {
                    Owner.AdoptNode(child);
                    InsertBefore((Node)child, null, false);
                }
            }
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#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);

            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);
        }
示例#6
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);
        }