public override XmlNode Item(int index)
        {
            XmlNode requestedNode = null;

            // Return null if index is out of range. by  DOM design.
            if (Count <= index)
            {
                return(null);
            }

            // Instead of checking for && index < Count which has to walk
            // the whole list to get a count, we'll just keep a count since
            // we have to walk the list anyways to get to index.
            if ((index >= 0) && (parent.LastLinkedChild != null))
            {
                XmlLinkedNode currentChild = parent.LastLinkedChild.NextLinkedSibling;
                int           count        = 0;

                while ((count < index) && !Object.ReferenceEquals(currentChild, parent.LastLinkedChild))
                {
                    currentChild = currentChild.NextLinkedSibling;
                    count++;
                }

                if (count == index)
                {
                    requestedNode = currentChild;
                }
            }

            return(requestedNode);
        }
 internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
 {
     XmlNodeChangedEventArgs insertEventArgsForLoad = doc.GetInsertEventArgsForLoad(newChild, this);
     if (insertEventArgsForLoad != null)
     {
         doc.BeforeEvent(insertEventArgsForLoad);
     }
     XmlLinkedNode nextNode = (XmlLinkedNode) newChild;
     if ((this.lastChild == null) || (this.lastChild == this))
     {
         nextNode.next = nextNode;
         this.lastChild = nextNode;
         nextNode.SetParentForLoad(this);
     }
     else
     {
         XmlLinkedNode lastChild = this.lastChild;
         nextNode.next = lastChild.next;
         lastChild.next = nextNode;
         this.lastChild = nextNode;
         if (lastChild.IsText && nextNode.IsText)
         {
             XmlNode.NestTextNodes(lastChild, nextNode);
         }
         else
         {
             nextNode.SetParentForLoad(this);
         }
     }
     if (insertEventArgsForLoad != null)
     {
         doc.AfterEvent(insertEventArgsForLoad);
     }
     return nextNode;
 }
Ejemplo n.º 3
0
        internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
        {
            XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(newChild, this);

            if (args != null)
            {
                doc.BeforeEvent(args);
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (lastChild == null || lastChild == emptyElem)
            {
                newNode.next = newNode;
            }
            else
            {
                newNode.next   = lastChild.next;
                lastChild.next = newNode;
            }

            lastChild = newNode;
            newNode.SetParentForLoad(this);

            if (args != null)
            {
                doc.AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 4
0
        //the function is provided only at Load time to speed up Load process
        internal virtual XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
        {
            XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(newChild, this);

            if (args != null)
            {
                doc.BeforeEvent(args);
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (LastNode == null)
            {
                newNode.next = newNode;
            }
            else
            {
                newNode.next  = LastNode.next;
                LastNode.next = newNode;
            }

            LastNode = newNode;
            newNode.SetParentForLoad(this);

            if (args != null)
            {
                doc.AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 5
0
 internal XmlElement(XmlName name, bool empty, XmlDocument doc) : base(doc)
 {
     Debug.Assert(name != null);
     if (!doc.IsLoading)
     {
         XmlDocument.CheckName(name.Prefix);
         XmlDocument.CheckName(name.LocalName);
     }
     if (name.LocalName == "")
     {
         throw new ArgumentException(Res.GetString(Res.Xdom_Empty_LocalName));
     }
     if (name.Prefix.Length >= 3 && (!doc.IsLoading) && String.Compare(name.Prefix, 0, "xml", 0, 3, true, CultureInfo.InvariantCulture) == 0)
     {
         throw new ArgumentException(Res.GetString(Res.Xdom_Ele_Prefix));
     }
     this.name = name;
     if (empty)
     {
         lastChild = emptyElem;
     }
     else
     {
         lastChild = null;
     }
 }
            public virtual bool MoveNext()
            {
                bool movedNext = true;

                if (parent.LastLinkedChild == null)
                {
                    movedNext = false;
                }
                else if (currentChild == null)
                {
                    currentChild = parent.LastLinkedChild.NextLinkedSibling;
                }
                else
                {
                    if (Object.ReferenceEquals(currentChild, parent.LastLinkedChild))
                    {
                        movedNext      = false;
                        passedLastNode = true;
                    }
                    else
                    {
                        currentChild = currentChild.NextLinkedSibling;
                    }
                }

                return(movedNext);
            }
Ejemplo n.º 7
0
        /// <include file='doc\XmlNode.uex' path='docs/doc[@for="XmlNode.RemoveChild"]/*' />
        /// <devdoc>
        ///    <para>Removes specified child node.</para>
        /// </devdoc>
        public virtual XmlNode RemoveChild(XmlNode oldChild)
        {
            if (!IsContainer)
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Remove_Contain));
            }

            if (oldChild.ParentNode != this)
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Remove_Child));
            }

            XmlLinkedNode oldNode = (XmlLinkedNode)oldChild;

            XmlNodeChangedEventArgs args = GetEventArgs(oldNode, this, null, XmlNodeChangedAction.Remove);

            if (args != null)
            {
                BeforeEvent(args);
            }

            if (oldNode == FirstChild)
            {
                if (LastNode.next == LastNode)
                {
                    LastNode = null;
                }
                else
                {
                    LastNode.next = (XmlLinkedNode)FirstChild.NextSibling;
                }
            }
            else
            {
                XmlLinkedNode prev = (XmlLinkedNode)oldNode.PreviousSibling;

                prev.next = oldNode.next;

                if (oldNode == LastNode)
                {
                    LastNode = prev;
                }
            }

            oldNode.next = null;
            oldNode.SetParent(null);

            if (args != null)
            {
                AfterEvent(args);
            }

            return(oldChild);
        }
Ejemplo n.º 8
0
        XmlLinkedNode lastChild; // == this for empty elements otherwise it is the last child

        internal XmlElement( XmlName name, bool empty, XmlDocument doc ): base( doc ) {
            Debug.Assert(name!=null);
            this.parentNode = null;
            if ( !doc.IsLoading ) {
                XmlDocument.CheckName( name.Prefix );
                XmlDocument.CheckName( name.LocalName );
            }
            if (name.LocalName.Length == 0) 
                throw new ArgumentException(Res.GetString(Res.Xdom_Empty_LocalName));
            this.name = name;
            if (empty) {
                this.lastChild = this; 
            }
        }
Ejemplo n.º 9
0
 internal XmlElement( XmlName name, bool empty, XmlDocument doc ): base( doc ) {
     Debug.Assert(name!=null);
     if ( !doc.IsLoading ) {
         XmlDocument.CheckName( name.Prefix );
         XmlDocument.CheckName( name.LocalName );
     }
     if (name.LocalName == "") 
         throw new ArgumentException(Res.GetString(Res.Xdom_Empty_LocalName));
     if ( name.Prefix.Length >= 3 && (! doc.IsLoading) && String.Compare( name.Prefix, 0, "xml", 0, 3, true, CultureInfo.InvariantCulture) == 0 )
         throw new ArgumentException(Res.GetString(Res.Xdom_Ele_Prefix));
     this.name = name;
     if (empty)
         lastChild = emptyElem;
     else
         lastChild = null;
 }
Ejemplo n.º 10
0
        XmlLinkedNode lastChild; // == this for empty elements otherwise it is the last child

        internal XmlElement( XmlName name, bool empty, XmlDocument doc ): base( doc ) {
            Debug.Assert(name!=null);
            this.parentNode = null;
            if ( !doc.IsLoading ) {
                XmlDocument.CheckName( name.Prefix );
                XmlDocument.CheckName( name.LocalName );
            }
            if (name.LocalName.Length == 0) 
                throw new ArgumentException(Res.GetString(Res.Xdom_Empty_LocalName));
            if ( name.Prefix.Length >= 3 && (! doc.IsLoading) && String.Compare( name.Prefix, 0, "xml", 0, 3, StringComparison.OrdinalIgnoreCase ) == 0 )
                throw new ArgumentException(Res.GetString(Res.Xdom_Ele_Prefix));
            this.name = name;
            if (empty) {
                this.lastChild = this; 
            }
        }
 internal XmlElement(System.Xml.XmlName name, bool empty, XmlDocument doc) : base(doc)
 {
     base.parentNode = null;
     if (!doc.IsLoading)
     {
         XmlDocument.CheckName(name.Prefix);
         XmlDocument.CheckName(name.LocalName);
     }
     if (name.LocalName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("Xdom_Empty_LocalName"));
     }
     this.name = name;
     if (empty)
     {
         this.lastChild = this;
     }
 }
 internal XmlElement(System.Xml.XmlName name, bool empty, XmlDocument doc) : base(doc)
 {
     base.parentNode = null;
     if (!doc.IsLoading)
     {
         XmlDocument.CheckName(name.Prefix);
         XmlDocument.CheckName(name.LocalName);
     }
     if (name.LocalName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("Xdom_Empty_LocalName"));
     }
     this.name = name;
     if (empty)
     {
         this.lastChild = this;
     }
 }
Ejemplo n.º 13
0
        private XmlLinkedNode _lastChild; // == this for empty elements otherwise it is the last child

        internal XmlElement(XmlName name, bool empty, XmlDocument doc) : base(doc)
        {
            Debug.Assert(name != null);
            this.parentNode = null;
            if (!doc.IsLoading)
            {
                XmlDocument.CheckName(name.Prefix);
                XmlDocument.CheckName(name.LocalName);
            }
            if (name.LocalName.Length == 0)
            {
                throw new ArgumentException(SR.Xdom_Empty_LocalName);
            }
            _name = name;
            if (empty)
            {
                _lastChild = this;
            }
        }
Ejemplo n.º 14
0
        internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
        {
            Debug.Assert(doc == this);

            if (!IsValidChildType(newChild.NodeType))
            {
                throw new InvalidOperationException(SR.Xdom_Node_Insert_TypeConflict);
            }

            if (!CanInsertAfter(newChild, LastChild))
            {
                throw new InvalidOperationException(SR.Xdom_Node_Insert_Location);
            }

            XmlNodeChangedEventArgs args = GetInsertEventArgsForLoad(newChild, this);

            if (args != null)
            {
                BeforeEvent(args);
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (lastChild == null)
            {
                newNode.next = newNode;
            }
            else
            {
                newNode.next   = lastChild.next;
                lastChild.next = newNode;
            }

            lastChild = newNode;
            newNode.SetParentForLoad(this);

            if (args != null)
            {
                AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 15
0
        //the function is provided only at Load time to speed up Load process
        internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
        {
            XmlNodeChangedEventArgs?args = doc.GetInsertEventArgsForLoad(newChild, this);

            if (args != null)
            {
                doc.BeforeEvent(args);
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (_lastChild == null ||
                _lastChild == this)
            {                           // if LastNode == null
                newNode.next = newNode;
                _lastChild   = newNode; // LastNode = newNode;
                newNode.SetParentForLoad(this);
            }
            else
            {
                XmlLinkedNode refNode = _lastChild; // refNode = LastNode;
                newNode.next = refNode.next;
                refNode.next = newNode;
                _lastChild   = newNode; // LastNode = newNode;
                if (refNode.IsText &&
                    newNode.IsText)
                {
                    NestTextNodes(refNode, newNode);
                }
                else
                {
                    newNode.SetParentForLoad(this);
                }
            }

            if (args != null)
            {
                doc.AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 16
0
			public virtual bool MoveNext()
			{
				bool movedNext = true;

				if (parent.LastLinkedChild == null) {
					movedNext = false;
				}
				else if (currentChild == null) {
					currentChild = parent.LastLinkedChild.NextLinkedSibling;
				}
				else {
					if (Object.ReferenceEquals(currentChild, parent.LastLinkedChild)) {
						movedNext = false;
						passedLastNode = true;
					}
					else {
						currentChild = currentChild.NextLinkedSibling;
					}
				}

				return movedNext;
			}
Ejemplo n.º 17
0
            public virtual bool MoveNext()
            {
                bool result = true;

                if (this.parent.LastLinkedChild == null)
                {
                    result = false;
                }
                else if (this.currentChild == null)
                {
                    this.currentChild = this.parent.LastLinkedChild.NextLinkedSibling;
                }
                else if (object.ReferenceEquals(this.currentChild, this.parent.LastLinkedChild))
                {
                    result = false;
                    this.passedLastNode = true;
                }
                else
                {
                    this.currentChild = this.currentChild.NextLinkedSibling;
                }
                return(result);
            }
Ejemplo n.º 18
0
        XmlLinkedNode lastChild; // == this for empty elements otherwise it is the last child

        internal XmlElement(XmlName name, bool empty, XmlDocument doc) : base(doc)
        {
            Debug.Assert(name != null);
            this.parentNode = null;
            if (!doc.IsLoading)
            {
                XmlDocument.CheckName(name.Prefix);
                XmlDocument.CheckName(name.LocalName);
            }
            if (name.LocalName.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Empty_LocalName));
            }
            if (name.Prefix.Length >= 3 && (!doc.IsLoading) && String.Compare(name.Prefix, 0, "xml", 0, 3, StringComparison.OrdinalIgnoreCase) == 0)
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Ele_Prefix));
            }
            this.name = name;
            if (empty)
            {
                this.lastChild = this;
            }
        }
Ejemplo n.º 19
0
        internal virtual XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
        {
            XmlNodeChangedEventArgs insertEventArgsForLoad = doc.GetInsertEventArgsForLoad(newChild, this);

            if (insertEventArgsForLoad != null)
            {
                doc.BeforeEvent(insertEventArgsForLoad);
            }
            XmlLinkedNode lastNode = this.LastNode;
            XmlLinkedNode nextNode = (XmlLinkedNode)newChild;

            if (lastNode == null)
            {
                nextNode.next = nextNode;
                this.LastNode = nextNode;
                nextNode.SetParentForLoad(this);
            }
            else
            {
                nextNode.next = lastNode.next;
                lastNode.next = nextNode;
                this.LastNode = nextNode;
                if (lastNode.IsText && nextNode.IsText)
                {
                    NestTextNodes(lastNode, nextNode);
                }
                else
                {
                    nextNode.SetParentForLoad(this);
                }
            }
            if (insertEventArgsForLoad != null)
            {
                doc.AfterEvent(insertEventArgsForLoad);
            }
            return(nextNode);
        }
Ejemplo n.º 20
0
        public override XmlNode Item(int index)
        {
            XmlNode result = null;

            if (this.Count <= index)
            {
                return(null);
            }
            if (index >= 0 && this.parent.LastLinkedChild != null)
            {
                XmlLinkedNode nextLinkedSibling = this.parent.LastLinkedChild.NextLinkedSibling;
                int           num = 0;
                while (num < index && !object.ReferenceEquals(nextLinkedSibling, this.parent.LastLinkedChild))
                {
                    nextLinkedSibling = nextLinkedSibling.NextLinkedSibling;
                    num++;
                }
                if (num == index)
                {
                    result = nextLinkedSibling;
                }
            }
            return(result);
        }
Ejemplo n.º 21
0
        internal override XmlNode AppendChildForLoad( XmlNode newChild, XmlDocument doc ) {
            XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad( newChild, this );

            if (args != null)
                doc.BeforeEvent( args );

            XmlLinkedNode newNode = (XmlLinkedNode) newChild;

            if (lastChild == null || lastChild == emptyElem) {
                newNode.next = newNode;
            }
            else {
                newNode.next = lastChild.next;
                lastChild.next = newNode;
            }

            lastChild = newNode;
            newNode.SetParentForLoad( this );

            if (args != null)
                doc.AfterEvent( args );

            return newNode;
        }
Ejemplo n.º 22
0
 //This should be used only to create the emptyElem as above.
 private XmlElement(): base() {
     this.name = null;
     this.lastChild = null;            
 }
Ejemplo n.º 23
0
        // Adds the specified node to the end of the list of children of this node.
        public virtual XmlNode AppendChild(XmlNode newChild)
        {
            XmlDocument thisDoc = OwnerDocument;
            if (thisDoc == null)
            {
                thisDoc = this as XmlDocument;
            }
            if (!IsContainer)
                throw new InvalidOperationException(SR.Xdom_Node_Insert_Contain);

            if (this == newChild || AncestorNode(newChild))
                throw new ArgumentException(SR.Xdom_Node_Insert_Child);

            if (newChild.ParentNode != null)
                newChild.ParentNode.RemoveChild(newChild);

            XmlDocument childDoc = newChild.OwnerDocument;
            if (childDoc != null && childDoc != thisDoc && childDoc != this)
                throw new ArgumentException(SR.Xdom_Node_Insert_Context);

            // special case for doc-fragment.
            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                XmlNode first = newChild.FirstChild;
                XmlNode node = first;
                while (node != null)
                {
                    XmlNode next = node.NextSibling;
                    newChild.RemoveChild(node);
                    AppendChild(node);
                    node = next;
                }
                return first;
            }

            if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
                throw new InvalidOperationException(SR.Xdom_Node_Insert_TypeConflict);


            if (!CanInsertAfter(newChild, LastChild))
                throw new InvalidOperationException(SR.Xdom_Node_Insert_Location);

            string newChildValue = newChild.Value;
            XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, newChildValue, newChildValue, XmlNodeChangedAction.Insert);

            if (args != null)
                BeforeEvent(args);

            XmlLinkedNode refNode = LastNode;
            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (refNode == null)
            {
                newNode.next = newNode;
                LastNode = newNode;
                newNode.SetParent(this);
            }
            else
            {
                newNode.next = refNode.next;
                refNode.next = newNode;
                LastNode = newNode;
                newNode.SetParent(this);

                if (refNode.IsText)
                {
                    if (newNode.IsText)
                    {
                        NestTextNodes(refNode, newNode);
                    }
                }
            }

            if (args != null)
                AfterEvent(args);

            return newNode;
        }
Ejemplo n.º 24
0
        // Removes specified child node.
        public virtual XmlNode RemoveChild(XmlNode oldChild)
        {
            if (!IsContainer)
            {
                throw new InvalidOperationException(SR.Xdom_Node_Remove_Contain);
            }

            if (oldChild.ParentNode != this)
            {
                throw new ArgumentException(SR.Xdom_Node_Remove_Child);
            }

            XmlLinkedNode oldNode = (XmlLinkedNode)oldChild;

            string oldNodeValue          = oldNode.Value;
            XmlNodeChangedEventArgs args = GetEventArgs(oldNode, this, null, oldNodeValue, oldNodeValue, XmlNodeChangedAction.Remove);

            if (args != null)
            {
                BeforeEvent(args);
            }

            XmlLinkedNode lastNode = LastNode;

            if (oldNode == FirstChild)
            {
                if (oldNode == lastNode)
                {
                    LastNode     = null;
                    oldNode.next = null;
                    oldNode.SetParent(null);
                }
                else
                {
                    XmlLinkedNode nextNode = oldNode.next;

                    if (nextNode.IsText)
                    {
                        if (oldNode.IsText)
                        {
                            UnnestTextNodes(oldNode, nextNode);
                        }
                    }

                    lastNode.next = nextNode;
                    oldNode.next  = null;
                    oldNode.SetParent(null);
                }
            }
            else
            {
                if (oldNode == lastNode)
                {
                    XmlLinkedNode prevNode = (XmlLinkedNode)oldNode.PreviousSibling;
                    prevNode.next = oldNode.next;
                    LastNode      = prevNode;
                    oldNode.next  = null;
                    oldNode.SetParent(null);
                }
                else
                {
                    XmlLinkedNode prevNode = (XmlLinkedNode)oldNode.PreviousSibling;
                    XmlLinkedNode nextNode = oldNode.next;

                    if (nextNode.IsText)
                    {
                        if (prevNode.IsText)
                        {
                            NestTextNodes(prevNode, nextNode);
                        }
                        else
                        {
                            if (oldNode.IsText)
                            {
                                UnnestTextNodes(oldNode, nextNode);
                            }
                        }
                    }

                    prevNode.next = nextNode;
                    oldNode.next  = null;
                    oldNode.SetParent(null);
                }
            }

            if (args != null)
            {
                AfterEvent(args);
            }

            return(oldChild);
        }
Ejemplo n.º 25
0
 internal XmlLinkedNode(XmlDocument doc) : base(doc)
 {
     this.next = null;
 }
Ejemplo n.º 26
0
        public virtual XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
        {
            if ((this == newChild) || this.AncestorNode(newChild))
            {
                throw new ArgumentException(Res.GetString("Xdom_Node_Insert_Child"));
            }
            if (refChild == null)
            {
                return(this.AppendChild(newChild));
            }
            if (!this.IsContainer)
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_Contain"));
            }
            if (refChild.ParentNode != this)
            {
                throw new ArgumentException(Res.GetString("Xdom_Node_Insert_Path"));
            }
            if (newChild == refChild)
            {
                return(newChild);
            }
            XmlDocument ownerDocument = newChild.OwnerDocument;
            XmlDocument document2     = this.OwnerDocument;

            if (((ownerDocument != null) && (ownerDocument != document2)) && (ownerDocument != this))
            {
                throw new ArgumentException(Res.GetString("Xdom_Node_Insert_Context"));
            }
            if (!this.CanInsertBefore(newChild, refChild))
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_Location"));
            }
            if (newChild.ParentNode != null)
            {
                newChild.ParentNode.RemoveChild(newChild);
            }
            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                XmlNode firstChild = newChild.FirstChild;
                XmlNode oldChild   = firstChild;
                if (oldChild != null)
                {
                    newChild.RemoveChild(oldChild);
                    this.InsertBefore(oldChild, refChild);
                    this.InsertAfter(newChild, oldChild);
                }
                return(firstChild);
            }
            if (!(newChild is XmlLinkedNode) || !this.IsValidChildType(newChild.NodeType))
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_TypeConflict"));
            }
            XmlLinkedNode           prevNode = (XmlLinkedNode)newChild;
            XmlLinkedNode           nextNode = (XmlLinkedNode)refChild;
            string                  oldValue = newChild.Value;
            XmlNodeChangedEventArgs args     = this.GetEventArgs(newChild, newChild.ParentNode, this, oldValue, oldValue, XmlNodeChangedAction.Insert);

            if (args != null)
            {
                this.BeforeEvent(args);
            }
            if (nextNode == this.FirstChild)
            {
                prevNode.next      = nextNode;
                this.LastNode.next = prevNode;
                prevNode.SetParent(this);
                if (prevNode.IsText && nextNode.IsText)
                {
                    NestTextNodes(prevNode, nextNode);
                }
            }
            else
            {
                XmlLinkedNode previousSibling = (XmlLinkedNode)nextNode.PreviousSibling;
                prevNode.next        = nextNode;
                previousSibling.next = prevNode;
                prevNode.SetParent(this);
                if (previousSibling.IsText)
                {
                    if (prevNode.IsText)
                    {
                        NestTextNodes(previousSibling, prevNode);
                        if (nextNode.IsText)
                        {
                            NestTextNodes(prevNode, nextNode);
                        }
                    }
                    else if (nextNode.IsText)
                    {
                        UnnestTextNodes(previousSibling, nextNode);
                    }
                }
                else if (prevNode.IsText && nextNode.IsText)
                {
                    NestTextNodes(prevNode, nextNode);
                }
            }
            if (args != null)
            {
                this.AfterEvent(args);
            }
            return(prevNode);
        }
Ejemplo n.º 27
0
        /// <include file='doc\XmlNode.uex' path='docs/doc[@for="XmlNode.InsertAfter"]/*' />
        /// <devdoc>
        ///    <para>Inserts the specified node immediately after the specified reference node.</para>
        /// </devdoc>
        public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild) {
            if (this == newChild || AncesterNode(newChild))
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Child));

            if (refChild == null)
                return PrependChild(newChild);

            if (!IsContainer)
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_Contain));

            if (refChild.ParentNode != this)
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Path));

            if (newChild == refChild)
                return newChild;

            XmlDocument childDoc = newChild.OwnerDocument;
            XmlDocument thisDoc = OwnerDocument;
            if (childDoc != null && childDoc != thisDoc && childDoc != this)
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Context));

            if (!CanInsertAfter( newChild, refChild ))
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_Location));

            if (newChild.ParentNode != null)
                newChild.ParentNode.RemoveChild( newChild );

            // special case for doc-fragment.
            if (newChild.NodeType == XmlNodeType.DocumentFragment) {
                XmlNode last = refChild;
                XmlNode first = newChild.FirstChild;
                XmlNode node = first;
                while (node != null) {
                    XmlNode next = node.NextSibling;
                    newChild.RemoveChild( node );
                    InsertAfter( node, last );
                    last = node;
                    node = next;
                }
                return first;
            }

            if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_TypeConflict));

            XmlLinkedNode newNode = (XmlLinkedNode) newChild;
            XmlLinkedNode refNode = (XmlLinkedNode) refChild;

            XmlNodeChangedEventArgs args = GetEventArgs( newChild, newChild.ParentNode, this, XmlNodeChangedAction.Insert );

            if (args != null)
                BeforeEvent( args );

            newNode.next = refNode.next;
            refNode.next = newNode;

            if (LastNode == refNode)
                LastNode = newNode;

            newNode.SetParent( this );

            if (args != null)
                AfterEvent( args );

            return newNode;
        }
Ejemplo n.º 28
0
        /// <include file='doc\XmlNode.uex' path='docs/doc[@for="XmlNode.RemoveChild"]/*' />
        /// <devdoc>
        ///    <para>Removes specified child node.</para>
        /// </devdoc>
        public virtual XmlNode RemoveChild(XmlNode oldChild) {
            if (!IsContainer)
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Remove_Contain));

            if (oldChild.ParentNode != this)
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Remove_Child));

            XmlLinkedNode oldNode = (XmlLinkedNode) oldChild;

            XmlNodeChangedEventArgs args = GetEventArgs( oldNode, this, null, XmlNodeChangedAction.Remove );

            if (args != null)
                BeforeEvent( args );

            if (oldNode == FirstChild) {
                if (LastNode.next == LastNode) {
                    LastNode = null;
                }
                else {
                    LastNode.next = (XmlLinkedNode) FirstChild.NextSibling;
                }
            }
            else {
                XmlLinkedNode prev = (XmlLinkedNode) oldNode.PreviousSibling;

                prev.next = oldNode.next;

                if (oldNode == LastNode)
                    LastNode = prev;
            }

            oldNode.next = null;
            oldNode.SetParent( null );

            if (args != null)
                AfterEvent( args );

            return oldChild;
        }
Ejemplo n.º 29
0
 internal Enumerator(IHasXmlChildNode parent)
 {
     this.currentChild   = null;
     this.parent         = parent;
     this.passedLastNode = false;
 }
Ejemplo n.º 30
0
 public virtual void Reset()
 {
     this.currentChild = null;
 }
Ejemplo n.º 31
0
        internal XmlNode RemoveChild(XmlNode oldChild, bool checkNodeType)
        {
            if (oldChild == null)
            {
                throw new NullReferenceException();
            }
            XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;

            if (oldChild.ParentNode != this)
            {
                throw new ArgumentException("The node to be removed is not a child of this node.");
            }

            if (checkNodeType)
            {
                ownerDoc.onNodeRemoving(oldChild, oldChild.ParentNode);
            }

            if (checkNodeType)
            {
                CheckNodeRemoval();
            }

            IHasXmlChildNode l = (IHasXmlChildNode)this;

            if (Object.ReferenceEquals(l.LastLinkedChild, l.LastLinkedChild.NextLinkedSibling) && Object.ReferenceEquals(l.LastLinkedChild, oldChild))
            {
                // If there is only one children, simply clear.
                l.LastLinkedChild = null;
            }
            else
            {
                XmlLinkedNode oldLinkedChild    = (XmlLinkedNode)oldChild;
                XmlLinkedNode beforeLinkedChild = l.LastLinkedChild;
                XmlLinkedNode firstChild        = (XmlLinkedNode)FirstChild;

                while (Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, l.LastLinkedChild) == false &&
                       Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild) == false)
                {
                    beforeLinkedChild = beforeLinkedChild.NextLinkedSibling;
                }

                if (Object.ReferenceEquals(beforeLinkedChild.NextLinkedSibling, oldLinkedChild) == false)
                {
                    throw new ArgumentException();
                }

                beforeLinkedChild.NextLinkedSibling = oldLinkedChild.NextLinkedSibling;

                // Each derived class may have its own l.LastLinkedChild, so we must set it explicitly.
                if (oldLinkedChild.NextLinkedSibling == firstChild)
                {
                    l.LastLinkedChild = beforeLinkedChild;
                }

                oldLinkedChild.NextLinkedSibling = null;
            }

            if (checkNodeType)
            {
                ownerDoc.onNodeRemoved(oldChild, oldChild.ParentNode);
            }
            oldChild.parentNode = null;                 // clear parent 'after' above logic.

            return(oldChild);
        }
Ejemplo n.º 32
0
        internal XmlNode InsertBefore(XmlNode newChild, XmlNode refChild, bool checkNodeType, bool raiseEvent)
        {
            if (checkNodeType)
            {
                CheckNodeInsertion(newChild, refChild);
            }

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

            IHasXmlChildNode l = (IHasXmlChildNode)this;

            XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument;

            if (raiseEvent)
            {
                ownerDoc.onNodeInserting(newChild, this);
            }

            if (newChild.ParentNode != null)
            {
                newChild.ParentNode.RemoveChild(newChild, checkNodeType);
            }

            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                // This recursively invokes events. (It is compatible with MS implementation.)
                XmlNode ret = null;
                while (newChild.FirstChild != null)
                {
                    var c = this.InsertBefore(newChild.FirstChild, refChild);
                    ret = ret ?? c;
                }
                return(ret);
            }
            else
            {
                XmlLinkedNode newLinkedChild = (XmlLinkedNode)newChild;
                newLinkedChild.parentNode = this;

                if (refChild == null)
                {
                    // newChild is the last child:
                    // * set newChild as NextSibling of the existing lastchild
                    // * set LastChild = newChild
                    // * set NextSibling of newChild as FirstChild
                    if (l.LastLinkedChild != null)
                    {
                        XmlLinkedNode formerFirst = (XmlLinkedNode)FirstChild;
                        l.LastLinkedChild.NextLinkedSibling = newLinkedChild;
                        l.LastLinkedChild = newLinkedChild;
                        newLinkedChild.NextLinkedSibling = formerFirst;
                    }
                    else
                    {
                        l.LastLinkedChild = newLinkedChild;
                        l.LastLinkedChild.NextLinkedSibling = newLinkedChild;                           // FirstChild
                    }
                }
                else
                {
                    // newChild is not the last child:
                    // * if newchild is first, then set next of lastchild is newChild.
                    //   otherwise, set next of previous sibling to newChild
                    // * set next of newChild to refChild
                    XmlLinkedNode prev = refChild.PreviousSibling as XmlLinkedNode;
                    if (prev == null)
                    {
                        l.LastLinkedChild.NextLinkedSibling = newLinkedChild;
                    }
                    else
                    {
                        prev.NextLinkedSibling = newLinkedChild;
                    }
                    newLinkedChild.NextLinkedSibling = refChild as XmlLinkedNode;
                }
                switch (newChild.NodeType)
                {
                case XmlNodeType.EntityReference:
                    ((XmlEntityReference)newChild).SetReferencedEntityContent();
                    break;

                case XmlNodeType.Entity:
                    break;

                case XmlNodeType.DocumentType:
                    break;
                }

                if (raiseEvent)
                {
                    ownerDoc.onNodeInserted(newChild, newChild.ParentNode);
                }
                return(newChild);
            }
        }
Ejemplo n.º 33
0
        //the function is provided only at Load time to speed up Load process
        internal virtual XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc) {
            XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad( newChild, this );

            if (args != null)
                doc.BeforeEvent( args );

            XmlLinkedNode newNode = (XmlLinkedNode) newChild;

            if (LastNode == null) {
                newNode.next = newNode;
            }
            else {
                newNode.next = LastNode.next;
                LastNode.next = newNode;
            }

            LastNode = newNode;
            newNode.SetParentForLoad( this );

            if (args != null)
                doc.AfterEvent( args );

            return newNode;
        }
Ejemplo n.º 34
0
			public virtual void Reset()
			{
				currentChild = null;
			}
Ejemplo n.º 35
0
 internal XmlLinkedNode()
 {
     this.next = null;
 }
Ejemplo n.º 36
0
        internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
        {
            Debug.Assert(doc == this);

            if (!IsValidChildType(newChild.NodeType))
                throw new InvalidOperationException(SR.Xdom_Node_Insert_TypeConflict);

            if (!CanInsertAfter(newChild, LastChild))
                throw new InvalidOperationException(SR.Xdom_Node_Insert_Location);

            XmlNodeChangedEventArgs args = GetInsertEventArgsForLoad(newChild, this);

            if (args != null)
                BeforeEvent(args);

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (_lastChild == null)
            {
                newNode.next = newNode;
            }
            else
            {
                newNode.next = _lastChild.next;
                _lastChild.next = newNode;
            }

            _lastChild = newNode;
            newNode.SetParentForLoad(this);

            if (args != null)
                AfterEvent(args);

            return newNode;
        }
Ejemplo n.º 37
0
        public virtual XmlNode AppendChild(XmlNode newChild)
        {
            XmlDocument ownerDocument = this.OwnerDocument;

            if (ownerDocument == null)
            {
                ownerDocument = this as XmlDocument;
            }
            if (!this.IsContainer)
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_Contain"));
            }
            if ((this == newChild) || this.AncestorNode(newChild))
            {
                throw new ArgumentException(Res.GetString("Xdom_Node_Insert_Child"));
            }
            if (newChild.ParentNode != null)
            {
                newChild.ParentNode.RemoveChild(newChild);
            }
            XmlDocument document2 = newChild.OwnerDocument;

            if (((document2 != null) && (document2 != ownerDocument)) && (document2 != this))
            {
                throw new ArgumentException(Res.GetString("Xdom_Node_Insert_Context"));
            }
            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                XmlNode nextSibling;
                XmlNode firstChild = newChild.FirstChild;
                for (XmlNode node2 = firstChild; node2 != null; node2 = nextSibling)
                {
                    nextSibling = node2.NextSibling;
                    newChild.RemoveChild(node2);
                    this.AppendChild(node2);
                }
                return(firstChild);
            }
            if (!(newChild is XmlLinkedNode) || !this.IsValidChildType(newChild.NodeType))
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_TypeConflict"));
            }
            if (!this.CanInsertAfter(newChild, this.LastChild))
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_Location"));
            }
            string oldValue = newChild.Value;
            XmlNodeChangedEventArgs args = this.GetEventArgs(newChild, newChild.ParentNode, this, oldValue, oldValue, XmlNodeChangedAction.Insert);

            if (args != null)
            {
                this.BeforeEvent(args);
            }
            XmlLinkedNode lastNode = this.LastNode;
            XmlLinkedNode nextNode = (XmlLinkedNode)newChild;

            if (lastNode == null)
            {
                nextNode.next = nextNode;
                this.LastNode = nextNode;
                nextNode.SetParent(this);
            }
            else
            {
                nextNode.next = lastNode.next;
                lastNode.next = nextNode;
                this.LastNode = nextNode;
                nextNode.SetParent(this);
                if (lastNode.IsText && nextNode.IsText)
                {
                    NestTextNodes(lastNode, nextNode);
                }
            }
            if (args != null)
            {
                this.AfterEvent(args);
            }
            return(nextNode);
        }
 internal XmlLinkedNode(XmlDocument doc) : base(doc)
 {
     this.next = null;
 }
Ejemplo n.º 39
0
        public virtual XmlNode RemoveChild(XmlNode oldChild)
        {
            if (!this.IsContainer)
            {
                throw new InvalidOperationException(Res.GetString("Xdom_Node_Remove_Contain"));
            }
            if (oldChild.ParentNode != this)
            {
                throw new ArgumentException(Res.GetString("Xdom_Node_Remove_Child"));
            }
            XmlLinkedNode           node     = (XmlLinkedNode)oldChild;
            string                  oldValue = node.Value;
            XmlNodeChangedEventArgs args     = this.GetEventArgs(node, this, null, oldValue, oldValue, XmlNodeChangedAction.Remove);

            if (args != null)
            {
                this.BeforeEvent(args);
            }
            XmlLinkedNode lastNode = this.LastNode;

            if (node == this.FirstChild)
            {
                if (node == lastNode)
                {
                    this.LastNode = null;
                    node.next     = null;
                    node.SetParent(null);
                }
                else
                {
                    XmlLinkedNode next = node.next;
                    if (next.IsText && node.IsText)
                    {
                        UnnestTextNodes(node, next);
                    }
                    lastNode.next = next;
                    node.next     = null;
                    node.SetParent(null);
                }
            }
            else if (node == lastNode)
            {
                XmlLinkedNode previousSibling = (XmlLinkedNode)node.PreviousSibling;
                previousSibling.next = node.next;
                this.LastNode        = previousSibling;
                node.next            = null;
                node.SetParent(null);
            }
            else
            {
                XmlLinkedNode prevNode = (XmlLinkedNode)node.PreviousSibling;
                XmlLinkedNode nextNode = node.next;
                if (nextNode.IsText)
                {
                    if (prevNode.IsText)
                    {
                        NestTextNodes(prevNode, nextNode);
                    }
                    else if (node.IsText)
                    {
                        UnnestTextNodes(node, nextNode);
                    }
                }
                prevNode.next = nextNode;
                node.next     = null;
                node.SetParent(null);
            }
            if (args != null)
            {
                this.AfterEvent(args);
            }
            return(oldChild);
        }
 internal XmlLinkedNode()
 {
     this.next = null;
 }
Ejemplo n.º 41
0
        // Inserts the specified node immediately after the specified reference node.
        public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
        {
            if (this == newChild || AncestorNode(newChild))
            {
                throw new ArgumentException(SR.Xdom_Node_Insert_Child);
            }

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

            if (!IsContainer)
            {
                throw new InvalidOperationException(SR.Xdom_Node_Insert_Contain);
            }

            if (refChild.ParentNode != this)
            {
                throw new ArgumentException(SR.Xdom_Node_Insert_Path);
            }

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

            XmlDocument childDoc = newChild.OwnerDocument;
            XmlDocument thisDoc  = OwnerDocument;

            if (childDoc != null && childDoc != thisDoc && childDoc != this)
            {
                throw new ArgumentException(SR.Xdom_Node_Insert_Context);
            }

            if (!CanInsertAfter(newChild, refChild))
            {
                throw new InvalidOperationException(SR.Xdom_Node_Insert_Location);
            }

            if (newChild.ParentNode != null)
            {
                newChild.ParentNode.RemoveChild(newChild);
            }

            // special case for doc-fragment.
            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                XmlNode last  = refChild;
                XmlNode first = newChild.FirstChild;
                XmlNode node  = first;
                while (node != null)
                {
                    XmlNode next = node.NextSibling;
                    newChild.RemoveChild(node);
                    InsertAfter(node, last);
                    last = node;
                    node = next;
                }
                return(first);
            }

            if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
            {
                throw new InvalidOperationException(SR.Xdom_Node_Insert_TypeConflict);
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;
            XmlLinkedNode refNode = (XmlLinkedNode)refChild;

            string newChildValue         = newChild.Value;
            XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, newChildValue, newChildValue, XmlNodeChangedAction.Insert);

            if (args != null)
            {
                BeforeEvent(args);
            }

            if (refNode == LastNode)
            {
                newNode.next = refNode.next;
                refNode.next = newNode;
                LastNode     = newNode;
                newNode.SetParent(this);

                if (refNode.IsText)
                {
                    if (newNode.IsText)
                    {
                        NestTextNodes(refNode, newNode);
                    }
                }
            }
            else
            {
                XmlLinkedNode nextNode = refNode.next;

                newNode.next = nextNode;
                refNode.next = newNode;
                newNode.SetParent(this);

                if (refNode.IsText)
                {
                    if (newNode.IsText)
                    {
                        NestTextNodes(refNode, newNode);
                        if (nextNode.IsText)
                        {
                            NestTextNodes(newNode, nextNode);
                        }
                    }
                    else
                    {
                        if (nextNode.IsText)
                        {
                            UnnestTextNodes(refNode, nextNode);
                        }
                    }
                }
                else
                {
                    if (newNode.IsText)
                    {
                        if (nextNode.IsText)
                        {
                            NestTextNodes(newNode, nextNode);
                        }
                    }
                }
            }


            if (args != null)
            {
                AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 42
0
			internal Enumerator (IHasXmlChildNode parent)
			{
				currentChild = null;
				this.parent = parent;
				passedLastNode = false;
			}
Ejemplo n.º 43
0
        // Removes specified child node.
        public virtual XmlNode RemoveChild(XmlNode oldChild)
        {
            if (!IsContainer)
                throw new InvalidOperationException(SR.Xdom_Node_Remove_Contain);

            if (oldChild.ParentNode != this)
                throw new ArgumentException(SR.Xdom_Node_Remove_Child);

            XmlLinkedNode oldNode = (XmlLinkedNode)oldChild;

            string oldNodeValue = oldNode.Value;
            XmlNodeChangedEventArgs args = GetEventArgs(oldNode, this, null, oldNodeValue, oldNodeValue, XmlNodeChangedAction.Remove);

            if (args != null)
                BeforeEvent(args);

            XmlLinkedNode lastNode = LastNode;

            if (oldNode == FirstChild)
            {
                if (oldNode == lastNode)
                {
                    LastNode = null;
                    oldNode.next = null;
                    oldNode.SetParent(null);
                }
                else
                {
                    XmlLinkedNode nextNode = oldNode.next;

                    if (nextNode.IsText)
                    {
                        if (oldNode.IsText)
                        {
                            UnnestTextNodes(oldNode, nextNode);
                        }
                    }

                    lastNode.next = nextNode;
                    oldNode.next = null;
                    oldNode.SetParent(null);
                }
            }
            else
            {
                if (oldNode == lastNode)
                {
                    XmlLinkedNode prevNode = (XmlLinkedNode)oldNode.PreviousSibling;
                    prevNode.next = oldNode.next;
                    LastNode = prevNode;
                    oldNode.next = null;
                    oldNode.SetParent(null);
                }
                else
                {
                    XmlLinkedNode prevNode = (XmlLinkedNode)oldNode.PreviousSibling;
                    XmlLinkedNode nextNode = oldNode.next;

                    if (nextNode.IsText)
                    {
                        if (prevNode.IsText)
                        {
                            NestTextNodes(prevNode, nextNode);
                        }
                        else
                        {
                            if (oldNode.IsText)
                            {
                                UnnestTextNodes(oldNode, nextNode);
                            }
                        }
                    }

                    prevNode.next = nextNode;
                    oldNode.next = null;
                    oldNode.SetParent(null);
                }
            }

            if (args != null)
                AfterEvent(args);

            return oldChild;
        }
Ejemplo n.º 44
0
 //This should be used only to create the emptyElem as above.
 private XmlElement() : base()
 {
     this.name      = null;
     this.lastChild = null;
 }
Ejemplo n.º 45
0
        /// <include file='doc\XmlNode.uex' path='docs/doc[@for="XmlNode.InsertBefore"]/*' />
        /// <devdoc>
        ///    <para>Inserts the specified node immediately before the specified reference node.</para>
        /// </devdoc>
        public virtual XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
        {
            if (this == newChild || AncesterNode(newChild))
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Child));
            }

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

            if (!IsContainer)
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_Contain));
            }

            if (refChild.ParentNode != this)
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Path));
            }

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

            XmlDocument childDoc = newChild.OwnerDocument;
            XmlDocument thisDoc  = OwnerDocument;

            if (childDoc != null && childDoc != thisDoc && childDoc != this)
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Context));
            }

            if (!CanInsertBefore(newChild, refChild))
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_Location));
            }

            if (newChild.ParentNode != null)
            {
                newChild.ParentNode.RemoveChild(newChild);
            }

            // special case for doc-fragment.
            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                XmlNode first = newChild.FirstChild;
                XmlNode node  = first;
                if (node != null)
                {
                    newChild.RemoveChild(node);
                    InsertBefore(node, refChild);
                    // insert the rest of the children after this one.
                    InsertAfter(newChild, node);
                }
                return(first);
            }

            if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_TypeConflict));
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;
            XmlLinkedNode refNode = (XmlLinkedNode)refChild;

            XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, XmlNodeChangedAction.Insert);

            if (args != null)
            {
                BeforeEvent(args);
            }

            if (refNode == FirstChild)
            {
                newNode.next  = (XmlLinkedNode)FirstChild;
                LastNode.next = newNode;
            }
            else
            {
                XmlLinkedNode prev = (XmlLinkedNode)refNode.PreviousSibling;
                newNode.next = refNode;
                prev.next    = newNode;
            }

            newNode.SetParent(this);

            if (args != null)
            {
                AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 46
0
        FrameworkElement FillLinkedNode(XmlLinkedNode linkedNode) {
            StackPanel commonPanel = new StackPanel();
            commonPanel.Orientation = Orientation.Vertical;

            if (linkedNode.Value != null) {
                commonPanel.Children.Add(FillSimpleValue(linkedNode));
            } else {
                Expander childExpander = new Expander();
                childExpander.ExpandDirection = ExpandDirection.Down;
                childExpander.Header = linkedNode.Name;
				
                StackPanel childPanel = new StackPanel();
                childPanel.Orientation = Orientation.Vertical;

                linkedNode.ForEach(lnode => {
                    var res = lnode as System.Xml.XmlLinkedNode;
                    childPanel.Children.Add(FillLinkedNode(res));
                });
                if (childPanel.Children.Count == 1)
                    commonPanel.Children.Add(childPanel);
                else {
                    childPanel.Margin = new Thickness(20, 0, 0, 0);
                    childExpander.Content = childPanel;
                    commonPanel.Children.Add(childExpander);
                }
            }
            return commonPanel;
        }
Ejemplo n.º 47
0
        /// <include file='doc\XmlNode.uex' path='docs/doc[@for="XmlNode.AppendChild"]/*' />
        /// <devdoc>
        ///    <para>Adds the specified node to the end of the list of children of
        ///       this node.</para>
        /// </devdoc>
        public virtual XmlNode AppendChild(XmlNode newChild)
        {
            XmlDocument thisDoc = OwnerDocument;

            if (thisDoc == null)
            {
                thisDoc = this as XmlDocument;
            }
            if (!IsContainer)
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_Contain));
            }

            if (this == newChild || AncesterNode(newChild))
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Child));
            }

            if (newChild.ParentNode != null)
            {
                newChild.ParentNode.RemoveChild(newChild);
            }

            XmlDocument childDoc = newChild.OwnerDocument;

            if (childDoc != null && childDoc != thisDoc && childDoc != this)
            {
                throw new ArgumentException(Res.GetString(Res.Xdom_Node_Insert_Context));
            }

            // special case for doc-fragment.
            if (newChild.NodeType == XmlNodeType.DocumentFragment)
            {
                XmlNode first = newChild.FirstChild;
                XmlNode node  = first;
                while (node != null)
                {
                    XmlNode next = node.NextSibling;
                    newChild.RemoveChild(node);
                    AppendChild(node);
                    node = next;
                }
                return(first);
            }

            if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_TypeConflict));
            }

            if (!CanInsertAfter(newChild, LastChild))
            {
                throw new InvalidOperationException(Res.GetString(Res.Xdom_Node_Insert_Location));
            }

            XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, XmlNodeChangedAction.Insert);

            if (args != null)
            {
                BeforeEvent(args);
            }

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (LastNode == null)
            {
                newNode.next = newNode;
            }
            else
            {
                newNode.next  = LastNode.next;
                LastNode.next = newNode;
            }

            LastNode = newNode;
            newNode.SetParent(this);

            if (args != null)
            {
                AfterEvent(args);
            }

            return(newNode);
        }
Ejemplo n.º 48
0
        FrameworkElement FillSimpleValue(XmlLinkedNode linkedNode) {
            StackPanel nsp = new StackPanel();
            nsp.Orientation = Orientation.Horizontal;
            nsp.Children.Add(new Label() { MinWidth = 100, Content = linkedNode.ParentNode.Name });
			//TextBlock tb = new TextBlock();
			//tb.MinWidth = 50;
			//tb.CreateBinding(TextBlock.TextProperty, linkedNode, x => x.Value, (m, v) => { m.Value = v; });
            nsp.Children.Add(new TextBox() { MinWidth = 50, Text = linkedNode.Value });

            return nsp;
        }
Ejemplo n.º 49
0
        //the function is provided only at Load time to speed up Load process
        internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc) {
            XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad( newChild, this );

            if (args != null)
                doc.BeforeEvent( args );

            XmlLinkedNode newNode = (XmlLinkedNode)newChild;

            if (lastChild == null) { // if LastNode == null
                newNode.next = newNode;
                lastChild = newNode;
                newNode.SetParentForLoad(this);
            }
            else {
                XmlLinkedNode refNode = lastChild; // refNode = LastNode;
                newNode.next = refNode.next;
                refNode.next = newNode;
                lastChild = newNode; // LastNode = newNode;
                if (refNode.IsText
                    && newNode.IsText) {
                    NestTextNodes(refNode, newNode);
                }
                else {
                    newNode.SetParentForLoad(this);
                }
            }

            if (args != null)
                doc.AfterEvent( args );

            return newNode;
        }
 internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
 {
     if (!this.IsValidChildType(newChild.NodeType))
     {
         throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_TypeConflict"));
     }
     if (!this.CanInsertAfter(newChild, this.LastChild))
     {
         throw new InvalidOperationException(Res.GetString("Xdom_Node_Insert_Location"));
     }
     XmlNodeChangedEventArgs insertEventArgsForLoad = this.GetInsertEventArgsForLoad(newChild, this);
     if (insertEventArgsForLoad != null)
     {
         this.BeforeEvent(insertEventArgsForLoad);
     }
     XmlLinkedNode node = (XmlLinkedNode) newChild;
     if (this.lastChild == null)
     {
         node.next = node;
     }
     else
     {
         node.next = this.lastChild.next;
         this.lastChild.next = node;
     }
     this.lastChild = node;
     node.SetParentForLoad(this);
     if (insertEventArgsForLoad != null)
     {
         this.AfterEvent(insertEventArgsForLoad);
     }
     return node;
 }