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); }
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 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); }
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); } }
public virtual void Reset() { currentChild = null; }
internal Enumerator(IHasXmlChildNode parent) { currentChild = null; this.parent = parent; passedLastNode = false; }