XmlAttributeCollection.ItemOf[] Propiedad

Definición

Obtiene el atributo con el nombre o índice especificado.

Sobrecargas

ItemOf[Int32]

Obtiene el atributo que tiene el índice especificado.

ItemOf[String]

Obtiene el atributo con el nombre especificado.

ItemOf[String, String]

Obtiene el atributo que tiene el nombre local e Identificador uniforme de recursos (URI) de espacio de nombres especificados.

ItemOf[Int32]

Obtiene el atributo que tiene el índice especificado.

public:
 property System::Xml::XmlAttribute ^ default[int] { System::Xml::XmlAttribute ^ get(int i); };
public:
 virtual property System::Xml::XmlAttribute ^ default[int] { System::Xml::XmlAttribute ^ get(int i); };
public System.Xml.XmlAttribute this[int i] { get; }
public virtual System.Xml.XmlAttribute this[int i] { get; }
member this.ItemOf(int) : System.Xml.XmlAttribute
Default Public ReadOnly Property ItemOf(i As Integer) As XmlAttribute
Default Public Overridable ReadOnly Property ItemOf(i As Integer) As XmlAttribute

Parámetros

i
Int32

Índice del atributo.

Valor de propiedad

XmlAttribute

Atributo en el índice especificado.

Excepciones

El índice a pasándose está fuera del intervalo.

Ejemplos

En el ejemplo siguiente se muestran todos los atributos de la colección.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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();

   }
}
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();
    }
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()
  
    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")      

    'Create an attribute collection.
    Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes

    Console.WriteLine("Display all the attributes in the collection...")
    Dim i as integer
    for i=0  to attrColl.Count-1
      Console.Write("{0} = ", attrColl.ItemOf(i).Name)
      Console.Write("{0}", attrColl.ItemOf(i).Value)
      Console.WriteLine()
    next
        
  end sub
end class

Comentarios

Esta propiedad es una extensión de Microsoft para Document Object Model (DOM). Equivale a llamar a XmlNamedNodeMap.Item.

Consulte también

Se aplica a

ItemOf[String]

Obtiene el atributo con el nombre especificado.

public:
 property System::Xml::XmlAttribute ^ default[System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ name); };
public:
 virtual property System::Xml::XmlAttribute ^ default[System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ name); };
public System.Xml.XmlAttribute this[string name] { get; }
public System.Xml.XmlAttribute? this[string name] { get; }
public virtual System.Xml.XmlAttribute this[string name] { get; }
member this.ItemOf(string) : System.Xml.XmlAttribute
Default Public ReadOnly Property ItemOf(name As String) As XmlAttribute
Default Public Overridable ReadOnly Property ItemOf(name As String) As XmlAttribute

Parámetros

name
String

Nombre completo del atributo.

Valor de propiedad

XmlAttribute

Atributo con el nombre especificado. Si el atributo no existe, esta propiedad devuelve null.

Ejemplos

En el ejemplo siguiente se quita un atributo del documento.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   XmlDocument^ doc = gcnew 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 );
}
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);
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()
  
    Dim doc as XmlDocument = 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.  
    Dim attrColl as XmlAttributeCollection = doc.DocumentElement.Attributes
    attrColl.Remove(attrColl.ItemOf("genre"))

    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.OuterXml)

  end sub
end class

Comentarios

Esta propiedad es una extensión de Microsoft para Document Object Model (DOM). Equivale a llamar a GetNamedItem.

Se aplica a

ItemOf[String, String]

Obtiene el atributo que tiene el nombre local e Identificador uniforme de recursos (URI) de espacio de nombres especificados.

public:
 property System::Xml::XmlAttribute ^ default[System::String ^, System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ localName, System::String ^ namespaceURI); };
public:
 virtual property System::Xml::XmlAttribute ^ default[System::String ^, System::String ^] { System::Xml::XmlAttribute ^ get(System::String ^ localName, System::String ^ namespaceURI); };
public System.Xml.XmlAttribute this[string localName, string namespaceURI] { get; }
public System.Xml.XmlAttribute? this[string localName, string? namespaceURI] { get; }
public virtual System.Xml.XmlAttribute this[string localName, string namespaceURI] { get; }
member this.ItemOf(string * string) : System.Xml.XmlAttribute
Default Public ReadOnly Property ItemOf(localName As String, namespaceURI As String) As XmlAttribute
Default Public Overridable ReadOnly Property ItemOf(localName As String, namespaceURI As String) As XmlAttribute

Parámetros

localName
String

Nombre local del atributo.

namespaceURI
String

URI de espacio de nombres del atributo.

Valor de propiedad

XmlAttribute

Atributo con el nombre local y el URI del espacio de nombres especificados. Si el atributo no existe, esta propiedad devuelve null.

Comentarios

Esta propiedad es una extensión de Microsoft para Document Object Model (DOM). Equivale a llamar a GetNamedItem.

Se aplica a