public class XmlAttributeCollection : XmlNamedNodeMap, ICollection
|
Count (inherited from System.Xml.XmlNamedNodeMap) |
Read-only See base class member description: System.Xml.XmlNamedNodeMap.Count Gets the number of nodes in the XmlNamedNodeMap. |
ItemOf | Read-only Overloaded: ItemOf Gets the attribute with the specified name. |
ItemOf | Read-only Overloaded: ItemOf Gets the attribute with the specified index. |
ItemOf | Read-only Overloaded: ItemOf Gets the attribute with the specified local name and namespace URI. |
Append | Inserts the specified attribute as the last node in the collection. |
CopyTo | Copies all the XmlAttribute objects from this collection into the given array. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetEnumerator (inherited from System.Xml.XmlNamedNodeMap) |
See base class member description: System.Xml.XmlNamedNodeMap.GetEnumerator Provides support for the "foreach" style iteration over the collection of nodes in the XmlNamedNodeMap. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetNamedItem (inherited from System.Xml.XmlNamedNodeMap) |
Overloaded:GetNamedItem(string name) See base class member description: System.Xml.XmlNamedNodeMap.GetNamedItemRetrieves an XmlNode specified by name. |
GetNamedItem (inherited from System.Xml.XmlNamedNodeMap) |
Overloaded:GetNamedItem(string localName, string namespaceURI) See base class member description: System.Xml.XmlNamedNodeMap.GetNamedItemRetrieves a node with the matching XmlNode.LocalName and XmlNode.NamespaceURI. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
InsertAfter | Inserts the specified attribute immediately after the specified reference attribute. |
InsertBefore | Inserts the specified attribute immediately before the specified reference attribute. |
Item (inherited from System.Xml.XmlNamedNodeMap) |
See base class member description: System.Xml.XmlNamedNodeMap.Item Retrieves the node at the specified index in the XmlNamedNodeMap. |
Prepend | Inserts the specified attribute as the first node in the collection. |
Remove | Removes the specified attribute from the collection. |
RemoveAll | Removes all attributes from the collection. |
RemoveAt | Removes the attribute corresponding to the specified index from the collection. |
RemoveNamedItem (inherited from System.Xml.XmlNamedNodeMap) |
Overloaded:RemoveNamedItem(string name) See base class member description: System.Xml.XmlNamedNodeMap.RemoveNamedItemRemoves the node from the XmlNamedNodeMap. |
RemoveNamedItem (inherited from System.Xml.XmlNamedNodeMap) |
Overloaded:RemoveNamedItem(string localName, string namespaceURI) See base class member description: System.Xml.XmlNamedNodeMap.RemoveNamedItemRemoves a node with the matching XmlNode.LocalName and XmlNode.NamespaceURI. |
SetNamedItem | Overridden: Adds a XmlNode using its XmlNode.Name property |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public virtual int Count {get;}
|
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' publicationdate='1997'> " + " <title>Pride And Prejudice</title>" + "</book>"); XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; Console.WriteLine("Display all the attributes for this book..."); for (int i=0; i < attrColl.Count; i++) { Console.WriteLine("{0} = {1}", attrColl.Item(i).Name, attrColl.Item(i).Value); } } }
No member name
public virtual XmlAttribute this[string name] {get;}
|
name
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create an attribute collection and remove an attribute //from the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.Remove(attrColl["genre"]); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
No member name
public virtual XmlAttribute this[int i] {get;}
|
i
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create an attribute collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; Console.WriteLine("Display all the attributes in the collection...\r\n"); for (int i=0; i < attrColl.Count; i++) { Console.Write("{0} = ", attrColl[i].Name); Console.Write("{0}", attrColl[i].Value); Console.WriteLine(); } } }
No member name
public virtual XmlAttribute this[string localName, string namespaceURI] {get;}
|
localName
namespaceURI
public virtual XmlAttribute Append( |
node
Exception Type | Condition |
---|---|
ArgumentException | node was created from a document different from the one that created this collection. |
This method is a Microsoft extension to the Document Object Model (DOM).
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create a new attribute. XmlAttribute newAttr = doc.CreateAttribute("genre"); newAttr.Value = "novel"; //Create an attribute collection and add the new attribute //to the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.Append(newAttr); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
public void CopyTo( |
array
index
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create an attribute collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; //Declare the array. XmlAttribute[] array = new XmlAttribute[2]; int index=0; //Copy all the attributes into the array. attrColl.CopyTo(array, index); Console.WriteLine("Display all the attributes in the array.."); foreach (XmlAttribute attr in array){ Console.WriteLine("{0} = {1}",attr.Name,attr.Value); } } }
~XmlAttributeCollection(); |
public virtual IEnumerator GetEnumerator(); |
using System; using System.IO; using System.Xml; using System.Collections; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' publicationdate='1997' " + " ISBN='1-861001-57-5'>" + " <title>Pride And Prejudice</title>" + "</book>"); XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; Console.WriteLine("Display all the attributes for this book..."); IEnumerator ienum = attrColl.GetEnumerator(); while (ienum.MoveNext()) { XmlAttribute attr = (XmlAttribute)ienum.Current; Console.WriteLine("{0} = {1}", attr.Name, attr.Value); } } }
public virtual int GetHashCode(); |
name
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' publicationdate='1997'> " + " <title>Pride And Prejudice</title>" + "</book>"); XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; //Change the value for the genre attribute. XmlAttribute attr = (XmlAttribute)attrColl.GetNamedItem("genre"); attr.Value = "fiction"; Console.WriteLine("Display the modified XML..."); Console.WriteLine(doc.OuterXml); } }
localName
namespaceURI
public Type GetType(); |
public virtual XmlAttribute InsertAfter( |
newNode
refNode
Exception Type | Condition |
---|---|
ArgumentException | The newNode was created from a document different from the one that created this collection. Or the refNode is not a member of this collection. |
This method is a Microsoft extension to the Document Object Model (DOM).
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create a new attribute. XmlAttribute newAttr = doc.CreateAttribute("genre"); newAttr.Value = "novel"; //Create an attribute collection and add the new attribute //to the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.InsertAfter(newAttr, attrColl[0]); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
public virtual XmlAttribute InsertBefore( |
newNode
refNode
Exception Type | Condition |
---|---|
ArgumentException | The newNode was created from a document different from the one that created this collection. Or the refNode is not a member of this collection. |
This method is a Microsoft extension to the Document Object Model (DOM).
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create a new attribute. XmlAttribute newAttr = doc.CreateAttribute("genre"); newAttr.Value = "novel"; //Create an attribute collection and add the new attribute //to the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.InsertBefore(newAttr, attrColl[0]); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
index
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' publicationdate='1997'> " + " <title>Pride And Prejudice</title>" + "</book>"); XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; Console.WriteLine("Display all the attributes for this book..."); for (int i=0; i < attrColl.Count; i++) { Console.WriteLine("{0} = {1}", attrColl.Item(i).Name, attrColl.Item(i).Value); } } }
protected object MemberwiseClone(); |
public virtual XmlAttribute Prepend( |
node
This method is a Microsoft extension to the Document Object Model (DOM).
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create a new attribute. XmlAttribute newAttr = doc.CreateAttribute("genre"); newAttr.Value = "novel"; //Create an attribute collection and add the new attribute //to the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.Prepend(newAttr); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
public virtual XmlAttribute Remove( |
node
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create an attribute collection and remove an attribute //from the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.Remove(attrColl["genre"]); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
public virtual void RemoveAll(); |
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create an attribute collection and remove all attributes //from the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.RemoveAll(); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
public virtual XmlAttribute RemoveAt( |
i
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create an attribute collection and remove an attribute //from the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.RemoveAt(0); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
name
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book genre='novel' publicationdate='1997'> " + " <title>Pride And Prejudice</title>" + "</book>"); XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; //Remove the publicationdate attribute. attrColl.RemoveNamedItem("publicationdate"); Console.WriteLine("Display the modified XML..."); Console.WriteLine(doc.OuterXml); } }
localName
namespaceURI
node
Exception Type | Condition |
---|---|
ArgumentException | node was created from a different XmlDocument than the one that created this collection. This XmlAttributeCollection is read-only. |
InvalidOperationException | node is an XmlAttribute that is already an attribute of another XmlElement object. To re-use attributes in other elements, you must clone the XmlAttribute objects you want to re-use. |
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new XmlDocument(); doc.LoadXml("<book ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" + "</book>"); //Create a new attribute. XmlAttribute newAttr = doc.CreateAttribute("genre"); newAttr.Value = "novel"; //Create an attribute collection and add the new attribute //to the collection. XmlAttributeCollection attrColl = doc.DocumentElement.Attributes; attrColl.SetNamedItem(newAttr); Console.WriteLine("Display the modified XML...\r\n"); Console.WriteLine(doc.OuterXml); } }
public virtual string ToString(); |