Пример #1
0
        internal HtmlNode InsertBefore(HtmlNode node, HtmlNode refChild)
        {
            Debug.Assert(m_XmlNode != null);
            Debug.Assert(m_XmlNode.ParentNode != null || (this is HtmlDocument));
            Debug.Assert(m_ChildNodeList != null);
            Debug.Assert(!(node is HtmlElement) || !(node as HtmlElement).IsEndTag, "If the child is an HtmlElement it must not be an 'End Tag'!");

            OnChildAppendingEventArgs ev = new OnChildAppendingEventArgs();

            if (OnChildAppending != null)
            {
                OnChildAppending(node, ref ev);
            }

            if (!ev.Cancel)
            {
                Debug.WriteLine("Adding a (" + node.Name + ") tag as a child of a (" + this.Name + ") tag.");

                node.ParentNode.ChildNodes.m_List.Remove(node);

                m_XmlNode.InsertBefore(node.m_XmlNode, refChild == null ? null : refChild.m_XmlNode);

                if (refChild == null)
                {
                    m_ChildNodeList.m_List.Add(node);
                }
                else
                {
                    int refIdx = m_ChildNodeList.m_List.IndexOf(refChild);
                    Debug.Assert(refIdx != -1);
                    m_ChildNodeList.m_List.Insert(refIdx, node);
                }


                if (OnChildAppended != null)
                {
                    OnChildAppended(node);
                }

                Debug.Assert(m_XmlNode == node.m_XmlNode.ParentNode);
                Debug.Assert(m_XmlNode.ParentNode != null || (this is HtmlDocument));

                return(node);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        internal HtmlNode AppendChild(HtmlNode node)
        {
            Debug.Assert(m_XmlNode != null);
            Debug.Assert(m_XmlNode.ParentNode != null || (this is HtmlDocument));
            Debug.Assert(m_ChildNodeList != null);
            Debug.Assert(!(node is HtmlElement) || !(node as HtmlElement).IsEndTag, "If the child is an HtmlElement it must not be an 'End Tag'!");

            OnChildAppendingEventArgs ev = new OnChildAppendingEventArgs();

            if (OnChildAppending != null)
            {
                OnChildAppending(node, ref ev);
            }

            if (!ev.Cancel)
            {
                Debug.WriteLine("Adding a (" + node.Name + ") tag as a child of a (" + this.Name + ") tag.");

                Debug.Assert(
                    (m_XmlNode == node.m_XmlNode.OwnerDocument) ||
                    (m_XmlNode.OwnerDocument == node.m_XmlNode.OwnerDocument)
                    );

                m_XmlNode.AppendChild(node.m_XmlNode);
                m_ChildNodeList.m_List.Add(node);

                if (OnChildAppended != null)
                {
                    OnChildAppended(node);
                }

                Debug.Assert(this.Equals(node.ParentNode));
                Debug.Assert(m_XmlNode == node.m_XmlNode.ParentNode);
                Debug.Assert(m_XmlNode.ParentNode != null || (this is HtmlDocument));

                return(node);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        private void ChildAppending(HtmlNode child, ref OnChildAppendingEventArgs e)
        {
            // NOTE: All "<!DOCTYPE" elements are *always* added to the HtmlDocument by the parser
            //       so we cannot miss a "<!DOCTYPE" on a wrong place
            if (child is HtmlDocTypeElement)
            {
                // Dont add the DocType element. This will stuff up the XPath queries
                e.Cancel = true;

                if (m_DocTypeElement == null)
                {
                    m_DocTypeElement = child as HtmlDocTypeElement;

                    //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
                    //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    //<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
                    //<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
                    //<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
                    //<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd">
                    //<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

                    // By default use Html 4.01 Strict
                    m_HtmlDtd = HtmlDtd.Html401;

                    if (!string.IsNullOrEmpty(m_DocTypeElement.PublicId))
                    {
                        string[] tokens = m_DocTypeElement.PublicId.Split(new string[] { "//" }, StringSplitOptions.None);

                        if (tokens.Length > 2)
                        {
                            if (tokens[1] == "W3C")
                            {
                                string dtd = tokens[2].Substring(4);

                                if (dtd == XHTML_ST)
                                {
                                    m_HtmlDtd = HtmlDtd.XhtmlStrict;
                                }

                                if (dtd == XHTML_TR)
                                {
                                    m_HtmlDtd = HtmlDtd.XhtmlTransitional;
                                }

                                if (dtd == XHTML_FR)
                                {
                                    m_HtmlDtd = HtmlDtd.XhtmlFrameset;
                                }

                                if (dtd == HTML_4_01)
                                {
                                    m_HtmlDtd = HtmlDtd.Html401;
                                }

                                if (dtd == HTML_4_01_TR)
                                {
                                    m_HtmlDtd = HtmlDtd.Html401Transitional;
                                }

                                if (dtd == HTML_4_01_FR)
                                {
                                    m_HtmlDtd = HtmlDtd.Html401Frameset;
                                }

                                if (dtd == HTML_3_2)
                                {
                                    m_HtmlDtd = HtmlDtd.Html32;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        private void ChildAppending(HtmlNode child, ref OnChildAppendingEventArgs e)
        {
            //Debug.Assert(child != null);

            //if (child != null && child is HtmlElement)
            //{
            //    if ((child as HtmlElement).IsStructureModuleElement)
            //    {
            //        Debug.Assert(child.Name != null);

            //        if (child.Name.Equals("BODY", StringComparison.CurrentCultureIgnoreCase))
            //        {
            //            // This is a <BODY> tag
            //            if (OwnerDocument.BodyElement == null)
            //                OwnerDocument.m_BodyElement = child as HtmlElement;
            //            else
            //            {
            //                // Don't add a second body tag, ignore it!
            //                e.Cancel = true;

            //                Debug.WriteLine("Ignoring a BODY tag because another BODY was already found at " + OwnerDocument.BodyElement.XPathLocation);
            //            }
            //        }

            //        if (child.Name.Equals("HEAD", StringComparison.CurrentCultureIgnoreCase))
            //        {
            //            // This is a <HEAD> tag
            //            if (OwnerDocument.HeadElement == null)
            //                OwnerDocument.m_HeadElement = child as HtmlElement;
            //            else
            //            {
            //                // Don't add a second head tag, ignore it!
            //                e.Cancel = true;

            //                Debug.WriteLine("Ignoring a HEAD tag because another HEAD was already found at " + OwnerDocument.HeadElement.XPathLocation);
            //            }
            //        }

            //        if (child.Name.Equals("HTML", StringComparison.CurrentCultureIgnoreCase))
            //        {
            //            // This is a <HTML> tag
            //            if (OwnerDocument.HtmlElement == null)
            //            {
            //                Debug.Assert(false);
            //                throw new HtmlParserException();

            //                // We should never come here. The HTML elements are handled by the HtmlParser's ProcessHtmlElement() routine
            //            }
            //            else
            //            {
            //                // Don't add a second html tag, ignore it!
            //                e.Cancel = true;

            //                Debug.WriteLine("Ignoring an HTML tag because another HTML was already found at " + OwnerDocument.HtmlElement.XPathLocation);
            //            }
            //        }
            //    }
            //}
            //else
            //{
            //    // It could be a comment, <%@, <![ ... etc node
            //}
        }