예제 #1
0
        public virtual INode InsertBefore(INode newChild, INode refChild)
        {
            // TODO - handle newChild already in tree

            if (newChild == null)
            {
                return(null);
            }
            if (!(newChild is DomNodeImpl))
            {
                throw new DomException(DomException.WrongDocument, "newChild not instanceof DomNodeImpl");
            }
            DomNodeImpl newCh = (DomNodeImpl)newChild;

            if (this.Adaptee.Type == Node.RootNode)
            {
                if (newCh.Adaptee.Type != Node.DocTypeTag && newCh.Adaptee.Type != Node.ProcInsTag)
                {
                    throw new DomException(DomException.HierarchyRequest, "newChild cannot be a child of this node");
                }
            }
            else if (this.Adaptee.Type == Node.StartTag)
            {
                if (newCh.Adaptee.Type != Node.StartTag && newCh.Adaptee.Type != Node.StartEndTag && newCh.Adaptee.Type != Node.CommentTag && newCh.Adaptee.Type != Node.TextNode && newCh.Adaptee.Type != Node.CDATATag)
                {
                    throw new DomException(DomException.HierarchyRequest, "newChild cannot be a child of this node");
                }
            }
            if (refChild == null)
            {
                Node.InsertNodeAtEnd(this.Adaptee, newCh.Adaptee);
                if (this.Adaptee.Type == Node.StartEndTag)
                {
                    this.Adaptee.Type = Node.StartTag;
                }
            }
            else
            {
                Node refNode = this.Adaptee.Content;
                while (refNode != null)
                {
                    if (refNode.Adapter == refChild)
                    {
                        break;
                    }
                    refNode = refNode.Next;
                }
                if (refNode == null)
                {
                    throw new DomException(DomException.NotFound, "refChild not found");
                }
                Node.InsertNodeBeforeElement(refNode, newCh.Adaptee);
            }
            return(newChild);
        }
예제 #2
0
        public virtual INode AppendChild(INode newChild)
        {
            // TODO - handle newChild already in tree

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

            if (!(newChild is DomNodeImpl))
            {
                throw new DomException(DomException.WrongDocument, "newChild not instanceof DomNodeImpl");
            }

            DomNodeImpl newCh = (DomNodeImpl)newChild;

            if (this.Adaptee.Type == Node.RootNode)
            {
                if (newCh.Adaptee.Type != Node.DocTypeTag && newCh.Adaptee.Type != Node.ProcInsTag)
                {
                    throw new DomException(DomException.HierarchyRequest, "newChild cannot be a child of this node");
                }
            }
            else if (this.Adaptee.Type == Node.StartTag)
            {
                if (newCh.Adaptee.Type != Node.StartTag && newCh.Adaptee.Type != Node.StartEndTag && newCh.Adaptee.Type != Node.CommentTag && newCh.Adaptee.Type != Node.TextNode && newCh.Adaptee.Type != Node.CDATATag)
                {
                    throw new DomException(DomException.HierarchyRequest, "newChild cannot be a child of this node");
                }
            }

            Node.InsertNodeAtEnd(Adaptee, newCh.Adaptee);

            if (Adaptee.Type == Node.StartEndTag)
            {
                Adaptee.Type = Node.StartTag;
            }

            return(newChild);
        }