public virtual XmlAttribute Remove(XmlAttribute node) #endif { if (IsReadOnly) { throw new ArgumentException("This attribute collection is read-only."); } if (node == null) { throw new ArgumentException("Specified node is null."); } if (node.OwnerDocument != ownerDocument) { throw new ArgumentException("Specified node is in a different document."); } if (node.OwnerElement != this.ownerElement) { throw new ArgumentException("The specified attribute is not contained in the element."); } XmlAttribute retAttr = null; for (int i = 0; i < Count; i++) { XmlAttribute attr = (XmlAttribute)Nodes [i]; if (attr == node) { retAttr = attr; break; } } if (retAttr != null) { ownerDocument.onNodeRemoving(node, ownerElement); base.RemoveNamedItem(retAttr.LocalName, retAttr.NamespaceURI); #if NOT_PFX RemoveIdenticalAttribute(retAttr); #endif ownerDocument.onNodeRemoved(node, ownerElement); } // If it is default, then directly create new attribute. #if NOT_PFX DTDAttributeDefinition def = retAttr.GetAttributeDefinition(); if (def != null && def.DefaultValue != null) { XmlAttribute attr = ownerDocument.CreateAttribute( retAttr.Prefix, retAttr.LocalName, retAttr.NamespaceURI); attr.Value = def.DefaultValue; attr.SetDefault(); this.SetNamedItem(attr); } #endif retAttr.AttributeOwnerElement = null; return(retAttr); }
/// <summary>Removes the specified attribute from the collection.</summary> /// <returns>The node removed or null if it is not found in the collection.</returns> /// <param name="node">The <see cref="T:System.Xml.XmlAttribute" /> to remove. </param> public XmlAttribute Remove(XmlAttribute node) { if (this.IsReadOnly) { throw new ArgumentException("This attribute collection is read-only."); } if (node == null) { throw new ArgumentException("Specified node is null."); } if (node.OwnerDocument != this.ownerDocument) { throw new ArgumentException("Specified node is in a different document."); } if (node.OwnerElement != this.ownerElement) { throw new ArgumentException("The specified attribute is not contained in the element."); } XmlAttribute xmlAttribute = null; for (int i = 0; i < this.Count; i++) { XmlAttribute xmlAttribute2 = (XmlAttribute)base.Nodes[i]; if (xmlAttribute2 == node) { xmlAttribute = xmlAttribute2; break; } } if (xmlAttribute != null) { this.ownerDocument.onNodeRemoving(node, this.ownerElement); base.RemoveNamedItem(xmlAttribute.LocalName, xmlAttribute.NamespaceURI); this.RemoveIdenticalAttribute(xmlAttribute); this.ownerDocument.onNodeRemoved(node, this.ownerElement); } DTDAttributeDefinition attributeDefinition = xmlAttribute.GetAttributeDefinition(); if (attributeDefinition != null && attributeDefinition.DefaultValue != null) { XmlAttribute xmlAttribute3 = this.ownerDocument.CreateAttribute(xmlAttribute.Prefix, xmlAttribute.LocalName, xmlAttribute.NamespaceURI, true, false); xmlAttribute3.Value = attributeDefinition.DefaultValue; xmlAttribute3.SetDefault(); this.SetNamedItem(xmlAttribute3); } xmlAttribute.AttributeOwnerElement = null; return(xmlAttribute); }
/// <summary>Removes the node from the XmlNamedNodeMap.</summary> /// <returns>The XmlNode removed from this XmlNamedNodeMap or null if a matching node was not found.</returns> /// <param name="name">The qualified name of the node to remove. The name is matched against the <see cref="P:System.Xml.XmlNode.Name" /> property of the matching node. </param> public virtual XmlNode RemoveNamedItem(string name) { if (this.nodeList == null) { return(null); } int i = 0; while (i < this.nodeList.Count) { XmlNode xmlNode = (XmlNode)this.nodeList[i]; if (xmlNode.Name == name) { if (xmlNode.IsReadOnly) { throw new InvalidOperationException("Cannot remove. This node is read only: " + name); } this.nodeList.Remove(xmlNode); XmlAttribute xmlAttribute = xmlNode as XmlAttribute; if (xmlAttribute != null) { DTDAttributeDefinition attributeDefinition = xmlAttribute.GetAttributeDefinition(); if (attributeDefinition != null && attributeDefinition.DefaultValue != null) { XmlAttribute xmlAttribute2 = xmlAttribute.OwnerDocument.CreateAttribute(xmlAttribute.Prefix, xmlAttribute.LocalName, xmlAttribute.NamespaceURI, true, false); xmlAttribute2.Value = attributeDefinition.DefaultValue; xmlAttribute2.SetDefault(); xmlAttribute.OwnerElement.SetAttributeNode(xmlAttribute2); } } return(xmlNode); } else { i++; } } return(null); }
public virtual XmlNode RemoveNamedItem(string name) { if (nodeList == null) { return(null); } for (int i = 0; i < nodeList.Count; i++) { XmlNode node = (XmlNode)nodeList [i]; if (node.Name == name) { if (node.IsReadOnly) { throw new InvalidOperationException("Cannot remove. This node is read only: " + name); } nodeList.Remove(node); // Since XmlAttributeCollection does not override // it while attribute have to keep it in the // collection, it adds to the collection immediately. XmlAttribute attr = node as XmlAttribute; #if NOT_PFX if (attr != null) { DTDAttributeDefinition def = attr.GetAttributeDefinition(); if (def != null && def.DefaultValue != null) { XmlAttribute newAttr = attr.OwnerDocument.CreateAttribute(attr.Prefix, attr.LocalName, attr.NamespaceURI, true, false); newAttr.Value = def.DefaultValue; newAttr.SetDefault(); attr.OwnerElement.SetAttributeNode(newAttr); } } #endif return(node); } } return(null); }