コード例 #1
0
 /// <summary>
 /// 根据ID获取节点,如果是BODY则直接获取BODY
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public HtmlNode GetElementById(string id)
 {
     if (string.Compare(id, "body", true) == 0)
     {
         return(SelectSingleNode("//body"));
     }
     return(CurrentDocument.GetElementbyId(id));
 }
コード例 #2
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="target"></param>
        /// <param name="index"></param>
        /// <param name="html"></param>
        public void Insert(string target, int index, string html)
        {
            var node       = HtmlNode.CreateNode(html);
            var targetNode = CurrentDocument.GetElementbyId(target);

            if (targetNode == null)
            {
                targetNode = CurrentDocument.DocumentNode.SelectSingleNode("//body");
            }
            if (targetNode.ChildNodes.Count >= index)
            {
                targetNode.ChildNodes.Insert(index, node);
            }
            else
            {
                targetNode.ChildNodes.Append(node);
            }
        }