예제 #1
0
파일: Node.cs 프로젝트: rrsc/AngleSharp
        public virtual Node ReplaceChild(Node newChild, Node oldChild)
        {
            if (newChild is Attr || newChild is Document || newChild.Contains(this))
                throw new DOMException(ErrorCode.HierarchyRequestError);
            else if (newChild == oldChild)
                return oldChild;
            else if (newChild.ParentNode != null)
                throw new DOMException(ErrorCode.InUse);

            var n = _children.Length;

            for (int i = 0; i < n; i++)
            {
                if (_children[i] == oldChild)
                {
                    RemoveChild(oldChild);
                    InsertChild(i, newChild);
                    return oldChild;
                }
            }

            return null;
        }
예제 #2
0
파일: Node.cs 프로젝트: rrsc/AngleSharp
        public virtual Node InsertBefore(Node newElement, Node referenceElement)
        {
            if (newElement is Attr || newElement is Document || newElement.Contains(this))
                throw new DOMException(ErrorCode.HierarchyRequestError);

            var n = _children.Length;

            for (int i = 0; i < n; i++)
            {
                if (_children[i] == referenceElement)
                    return InsertChild(i, newElement);
            }

            return AppendChild(newElement);
        }
예제 #3
0
파일: Node.cs 프로젝트: rrsc/AngleSharp
        public virtual Node InsertChild(Int32 index, Node child)
        {
            if (child is DocumentFragment)
            {
                var childs = child.ChildNodes;

                for (int i = 0; i < childs.Length; i++)
                    InsertChild(index + i, childs[i]);
            }
            else if (child is Attr || child is Document || child.Contains(this))
            {
                throw new DOMException(ErrorCode.HierarchyRequestError);
            }
            else
            {
                if (child.ParentNode != null)
                    throw new DOMException(ErrorCode.InUse);

                child._parent = this;
                child.OwnerDocument = _owner ?? (this as Document);
                _children.Insert(index, child);
            }

            return child;
        }
예제 #4
0
파일: Node.cs 프로젝트: rrsc/AngleSharp
        public virtual DocumentPosition CompareDocumentPosition(Node otherNode)
        {
            if (this == otherNode)
                return DocumentPosition.Same;

            if(this.OwnerDocument != otherNode.OwnerDocument)
            {
                return DocumentPosition.Disconnected | DocumentPosition.ImplementationSpecific |
                    (otherNode.GetHashCode() > this.GetHashCode() ? DocumentPosition.Following : DocumentPosition.Preceding);
            }
            else if (this.Contains(otherNode))
            {
                return DocumentPosition.ContainedBy | DocumentPosition.Following;
            }
            else if (otherNode.Contains(this))
            {
                return DocumentPosition.Contains | DocumentPosition.Preceding;
            }

            return CompareRelativePositionInNodeList(_owner.ChildNodes, this, otherNode);
        }