Exemple #1
0
        }                        // Used for Node.Clone().

        /// <summary>
        /// Create a valid, empty shell of a document, suitable for adding more elements to.
        /// </summary>
        /// <param name="baseUri">baseUri of document</param>
        /// <returns>document with html, head, and body elements.</returns>
        static public Document CreateShell(string baseUri)
        {
            if (baseUri == null)
            {
                throw new ArgumentNullException("baseUri");
            }

            Document doc  = new Document(baseUri);
            Element  html = doc.AppendElement("html");

            html.AppendElement("head");
            html.AppendElement("body");

            return(doc);
        }
Exemple #2
0
        /// <summary>
        /// Normalise the document. This happens after the parse phase so generally does not need to be called.
        /// Moves any text content that is not in the body element into the body.
        /// </summary>
        /// <returns>this document after normalisation</returns>
        public Document Normalise()
        {
            Element htmlEl = FindFirstElementByTagName("html", this);

            if (htmlEl == null)
            {
                htmlEl = AppendElement("html");
            }
            if (Head == null)
            {
                htmlEl.PrependElement("head");
            }
            if (Body == null)
            {
                htmlEl.AppendElement("body");
            }

            // pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care
            // of. do in inverse order to maintain text order.
            NormaliseTextNodes(Head);
            NormaliseTextNodes(htmlEl);
            NormaliseTextNodes(this);

            NormaliseStructure("head", htmlEl);
            NormaliseStructure("body", htmlEl);

            return(this);
        }