Beispiel #1
0
        /// <summary>
        /// Replaces the child node oldChild with newChild node.
        /// </summary>
        /// <param name="newChild">
        /// The new node to put in the child list. 
        /// </param>
        /// <param name="oldChild">
        /// The node being replaced in the list. 
        /// </param>
        /// <returns>
        /// The node replaced. 
        /// </returns>
        public HtmlNode ReplaceChild(HtmlNode newChild, HtmlNode oldChild)
        {
            if (newChild == null)
            {
                return this.RemoveChild(oldChild);
            }

            if (oldChild == null)
            {
                return this.AppendChild(newChild);
            }

            int index = -1;

            if (this.childnodes != null)
            {
                index = this.childnodes[oldChild];
            }

            if (index == -1)
            {
                throw new ArgumentException(HtmlDocument.HtmlExceptionRefNotChild);
            }

            if (this.childnodes != null)
            {
                this.childnodes.Replace(index, newChild);
            }

            this.OwnerDocument.SetIdForNode(null, oldChild.GetId());
            this.OwnerDocument.SetIdForNode(newChild, newChild.GetId());
            this.OuterChanged = true;
            this.InnerChanged = true;
            return newChild;
        }
Beispiel #2
0
        /// <summary>
        /// Adds the specified node to the end of the list of children of this node.
        /// </summary>
        /// <param name="newChild">
        /// The node to add. May not be null. 
        /// </param>
        /// <returns>
        /// The node added. 
        /// </returns>
        public HtmlNode AppendChild(HtmlNode newChild)
        {
            if (newChild == null)
            {
                throw new ArgumentNullException("newChild");
            }

            this.ChildNodes.Append(newChild);
            this.OwnerDocument.SetIdForNode(newChild, newChild.GetId());
            this.OuterChanged = true;
            this.InnerChanged = true;
            return newChild;
        }
Beispiel #3
0
        /// <summary>
        /// Inserts the specified node immediately before the specified reference node.
        /// </summary>
        /// <param name="newChild">
        /// The node to insert. May not be <c>null</c> . 
        /// </param>
        /// <param name="refChild">
        /// The node that is the reference node. The newChild is placed before this node. 
        /// </param>
        /// <returns>
        /// The node being inserted. 
        /// </returns>
        public HtmlNode InsertBefore(HtmlNode newChild, HtmlNode refChild)
        {
            if (newChild == null)
            {
                throw new ArgumentNullException("newChild");
            }

            if (refChild == null)
            {
                return this.AppendChild(newChild);
            }

            if (newChild == refChild)
            {
                return newChild;
            }

            int index = -1;

            if (this.childnodes != null)
            {
                index = this.childnodes[refChild];
            }

            if (index == -1)
            {
                throw new ArgumentException(HtmlDocument.HtmlExceptionRefNotChild);
            }

            if (this.childnodes != null)
            {
                this.childnodes.Insert(index, newChild);
            }

            this.OwnerDocument.SetIdForNode(newChild, newChild.GetId());
            this.OuterChanged = true;
            this.InnerChanged = true;
            return newChild;
        }