XmlTextReader.GetAttribute Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene el valor de un atributo .
Sobrecargas
| Nombre | Description |
|---|---|
| GetAttribute(Int32) |
Obtiene el valor del atributo con el índice especificado. |
| GetAttribute(String) |
Obtiene el valor del atributo con el nombre especificado. |
| GetAttribute(String, String) |
Obtiene el valor del atributo con el nombre local y el URI del espacio de nombres especificados. |
Comentarios
Nota:
Se recomienda crear XmlReader instancias mediante el XmlReader.Create método para aprovechar las nuevas funcionalidades.
GetAttribute(Int32)
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
Obtiene el valor del atributo con el índice especificado.
public:
override System::String ^ GetAttribute(int i);
public override string GetAttribute(int i);
override this.GetAttribute : int -> string
Public Overrides Function GetAttribute (i As Integer) As String
Parámetros
- i
- Int32
Índice del atributo. El índice es de base cero. (El primer atributo tiene el índice 0).
Devoluciones
Valor del atributo especificado.
Excepciones
El i parámetro es menor que 0 o mayor o igual que AttributeCount.
Comentarios
Nota:
Se recomienda crear XmlReader instancias mediante el XmlReader.Create método para aprovechar las nuevas funcionalidades.
Este método no mueve el lector.
Consulte también
Se aplica a
GetAttribute(String)
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
Obtiene el valor del atributo con el nombre especificado.
public:
override System::String ^ GetAttribute(System::String ^ name);
public override string? GetAttribute(string name);
public override string GetAttribute(string name);
override this.GetAttribute : string -> string
Public Overrides Function GetAttribute (name As String) As String
Parámetros
- name
- String
Nombre completo del atributo.
Devoluciones
Valor del atributo especificado. Si no se encuentra el atributo , null se devuelve.
Ejemplos
En el ejemplo siguiente se obtiene el valor del atributo ISBN.
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = null;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader("attrs.xml");
//Read the ISBN attribute.
reader.MoveToContent();
string isbn = reader.GetAttribute("ISBN");
Console.WriteLine("The ISBN value: " + isbn);
}
finally
{
if (reader != null)
reader.Close();
}
}
} // End class
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
'Load the reader with the XML file.
reader = New XmlTextReader("attrs.xml")
'Read the ISBN attribute.
reader.MoveToContent()
Dim isbn As String = reader.GetAttribute("ISBN")
Console.WriteLine("The ISBN value: " & isbn)
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
En el ejemplo se usa el archivo , attrs.xmlcomo entrada.
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
Comentarios
Nota:
Se recomienda crear XmlReader instancias mediante el XmlReader.Create método para aprovechar las nuevas funcionalidades.
Este método no mueve el lector.
Si el lector se coloca en un DocumentType nodo, este método se puede usar para obtener los literales PUBLIC y SYSTEM, por ejemplo, reader.GetAttribute("PUBLIC")
Consulte también
Se aplica a
GetAttribute(String, String)
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
- Source:
- XmlTextReader.cs
Obtiene el valor del atributo con el nombre local y el URI del espacio de nombres especificados.
public:
override System::String ^ GetAttribute(System::String ^ localName, System::String ^ namespaceURI);
public override string? GetAttribute(string localName, string? namespaceURI);
public override string GetAttribute(string localName, string namespaceURI);
override this.GetAttribute : string * string -> string
Public Overrides Function GetAttribute (localName As String, namespaceURI As String) As String
Parámetros
- localName
- String
Nombre local del atributo.
- namespaceURI
- String
Identificador URI del espacio de nombres del atributo.
Devoluciones
Valor del atributo especificado. Si no se encuentra el atributo , null se devuelve. Este método no mueve el lector.
Comentarios
Nota:
Se recomienda crear XmlReader instancias mediante el XmlReader.Create método para aprovechar las nuevas funcionalidades.
El siguiente XML contiene un atributo en un espacio de nombres específico:
<test xmlns:dt="urn:datatypes" dt:type="int"/>
Puede buscar el dt:type atributo mediante un argumento (prefijo y nombre local) o dos argumentos (nombre local y URI del espacio de nombres):
String dt = reader.GetAttribute("dt:type");
String dt2 = reader.GetAttribute("type","urn:datatypes");
Para buscar el xmlns:dt atributo, use uno de los argumentos siguientes:
String dt3 = reader.GetAttribute("xmlns:dt");
String dt4 = reader.GetAttribute("dt",http://www.w3.org/2000/xmlns/);
También puede obtener esta información mediante la Prefix propiedad .