Прочетете на английски Редактиране

Споделяне чрез


XmlAttributeCollection.ItemOf[] Property

Definition

Gets the attribute with the specified name or index.

Overloads

ItemOf[Int32]

Gets the attribute with the specified index.

ItemOf[String]

Gets the attribute with the specified name.

ItemOf[String, String]

Gets the attribute with the specified local name and namespace Uniform Resource Identifier (URI).

ItemOf[Int32]

Source:
XmlAttributeCollection.cs
Source:
XmlAttributeCollection.cs
Source:
XmlAttributeCollection.cs

Gets the attribute with the specified index.

C#
public System.Xml.XmlAttribute this[int i] { get; }
C#
public virtual System.Xml.XmlAttribute this[int i] { get; }

Parameters

i
Int32

The index of the attribute.

Property Value

The attribute at the specified index.

Exceptions

The index being passed in is out of range.

Examples

The following example displays all the attributes in the collection.

C#
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();
    }
  }
}

Remarks

This property is a Microsoft extension to the Document Object Model (DOM). It is equivalent to calling XmlNamedNodeMap.Item.

See also

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

ItemOf[String]

Source:
XmlAttributeCollection.cs
Source:
XmlAttributeCollection.cs
Source:
XmlAttributeCollection.cs

Gets the attribute with the specified name.

C#
public System.Xml.XmlAttribute this[string name] { get; }
C#
public System.Xml.XmlAttribute? this[string name] { get; }
C#
public virtual System.Xml.XmlAttribute this[string name] { get; }

Parameters

name
String

The qualified name of the attribute.

Property Value

The attribute with the specified name. If the attribute does not exist, this property returns null.

Examples

The following example removes an attribute from the document.

C#
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);
  }
}

Remarks

This property is a Microsoft extension to the Document Object Model (DOM). It is equivalent to calling GetNamedItem.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

ItemOf[String, String]

Source:
XmlAttributeCollection.cs
Source:
XmlAttributeCollection.cs
Source:
XmlAttributeCollection.cs

Gets the attribute with the specified local name and namespace Uniform Resource Identifier (URI).

C#
public System.Xml.XmlAttribute this[string localName, string namespaceURI] { get; }
C#
public System.Xml.XmlAttribute? this[string localName, string? namespaceURI] { get; }
C#
public virtual System.Xml.XmlAttribute this[string localName, string namespaceURI] { get; }

Parameters

localName
String

The local name of the attribute.

namespaceURI
String

The namespace URI of the attribute.

Property Value

The attribute with the specified local name and namespace URI. If the attribute does not exist, this property returns null.

Remarks

This property is a Microsoft extension to the Document Object Model (DOM). It is equivalent to calling GetNamedItem.

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0