HtmlAgilityPack.HtmlNode.ReplaceChild C# (CSharp) Method

ReplaceChild() public method

Replaces the child node oldChild with newChild node.
public ReplaceChild ( HtmlNode newChild, HtmlNode oldChild ) : HtmlNode
newChild HtmlNode The new node to put in the child list.
oldChild HtmlNode The node being replaced in the list.
return HtmlNode
		public HtmlNode ReplaceChild(HtmlNode newChild, HtmlNode oldChild)
		{
			if (newChild == null)
			{
				return RemoveChild(oldChild);
			}

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

			int index = -1;

			if (_childnodes != null)
			{
				index = _childnodes[oldChild];
			}

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

			_childnodes.Replace(index, newChild);

			_ownerdocument.SetIdForNode(null, oldChild.GetId());
			_ownerdocument.SetIdForNode(newChild, newChild.GetId());
			_outerchanged = true;
			_innerchanged = true;
			return newChild;
		}