Exemplo n.º 1
0
        /// <summary>
        /// 从表示节点的字符串解析出节点
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static HtmlNode ParseNode(string text)
        {
            int type = GetNodeStringType(text);

            if (type == 3)
            {
                return(HtmlNode.CreateTextNode(text));          //文本节点
            }
            string tagName = HtmlNode.GetNodeName(text);

            if (type == 0)
            {
                HtmlNode node = new HtmlNode(tagName);
                node.Attributes = ParseAttribute(text);
                return(node);
            }
            else if (type == 2)
            {
                HtmlNode node = HtmlNode.CreateClosedNode(tagName);
                node.Attributes = ParseAttribute(text);
                return(node);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public HtmlNode GetJsBlockNode()
        {
            HtmlNode scriptNode = new HtmlNode("script");

            scriptNode.Attributes["type"] = "text/javascript";
            HtmlNode txtNode = HtmlNode.CreateTextNode(this.ToString());

            scriptNode.Append(txtNode);
            return(scriptNode);
        }
Exemplo n.º 3
0
        public void InitStandardDocument(string title)
        {
            this._RootNode = new HtmlNode("html");
            HtmlNode head      = new HtmlNode("head");
            HtmlNode titleNode = new HtmlNode("title");

            if (title != "")
            {
                titleNode.Append(HtmlNode.CreateTextNode(title));          //标题非即添加文本节点
            }
            head.Append(titleNode);

            this.RootNode.Append(head);
            HtmlNode body = new HtmlNode("body");

            this.RootNode.Append(body);
            Head = head;
            Body = body;
        }