XmlReader.GetAttribute Método
Definição
Quando substituído em uma classe derivada, obtém o valor de um atributo.When overridden in a derived class, gets the value of an attribute.
Sobrecargas
GetAttribute(String, String) |
Quando substituído em uma classe derivada, obtém o valor do atributo com o LocalName e o NamespaceURI especificados.When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI. |
GetAttribute(Int32) |
Quando substituído em uma classe derivada, obtém o valor do atributo com o índice especificado.When overridden in a derived class, gets the value of the attribute with the specified index. |
GetAttribute(String) |
Quando substituído em uma classe derivada, obtém o valor do atributo com o Name especificado.When overridden in a derived class, gets the value of the attribute with the specified Name. |
GetAttribute(String, String)
Quando substituído em uma classe derivada, obtém o valor do atributo com o LocalName e o NamespaceURI especificados.When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI.
public:
abstract System::String ^ GetAttribute(System::String ^ name, System::String ^ namespaceURI);
public abstract string GetAttribute (string name, string namespaceURI);
public abstract string? GetAttribute (string name, string? namespaceURI);
abstract member GetAttribute : string * string -> string
Public MustOverride Function GetAttribute (name As String, namespaceURI As String) As String
Parâmetros
- name
- String
O nome local do atributo.The local name of the attribute.
- namespaceURI
- String
O URI do namespace do atributo.The namespace URI of the attribute.
Retornos
O valor do atributo especificado.The value of the specified attribute. Se o atributo não foi encontrado ou o valor é String.Empty
, null
será retornado.If the attribute is not found or the value is String.Empty
, null
is returned. Esse método não move o leitor.This method does not move the reader.
Exceções
name
é null
.name
is null
.
Um método XmlReader foi chamado antes do término de uma operação assíncrona anterior.An XmlReader method was called before a previous asynchronous operation finished. Nesse caso, InvalidOperationException será gerado com a mensagem “Uma operação assíncrona já está em andamento”.In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."
Comentários
O XML a seguir contém um atributo em um namespace específico:The following XML contains an attribute in a specific namespace:
<test xmlns:dt="urn:datatypes" dt:type="int"/>
Você pode pesquisar o dt:type
atributo usando um argumento (prefixo e nome local) ou dois argumentos (nome local e URI do namespace):You can lookup the dt:type
attribute using one argument (prefix and local name) or two arguments (local name and namespace URI):
String dt = reader.GetAttribute("dt:type");
String dt2 = reader.GetAttribute("type","urn:datatypes");
Para pesquisar o xmlns:dt
atributo, use um dos seguintes argumentos:To lookup the xmlns:dt
attribute, use one of the following arguments:
String dt3 = reader.GetAttribute("xmlns:dt");
String dt4 = reader.GetAttribute("dt",http://www.w3.org/2000/xmlns/);
Você também pode obter essas informações usando a Prefix propriedade.You can also get this information using the Prefix property.
Aplica-se a
GetAttribute(Int32)
Quando substituído em uma classe derivada, obtém o valor do atributo com o índice especificado.When overridden in a derived class, gets the value of the attribute with the specified index.
public:
abstract System::String ^ GetAttribute(int i);
public abstract string GetAttribute (int i);
abstract member GetAttribute : int -> string
Public MustOverride Function GetAttribute (i As Integer) As String
Parâmetros
- i
- Int32
O índice do atributo.The index of the attribute. O índice é baseado em zero.The index is zero-based. (O primeiro atributo tem índice 0.)(The first attribute has index 0.)
Retornos
O valor do atributo especificado.The value of the specified attribute. Esse método não move o leitor.This method does not move the reader.
Exceções
i
está fora do intervalo.i
is out of range. Ele deve ser não negativo e menor que o tamanho da coleção de atributos.It must be non-negative and less than the size of the attribute collection.
Um método XmlReader foi chamado antes do término de uma operação assíncrona anterior.An XmlReader method was called before a previous asynchronous operation finished. Nesse caso, InvalidOperationException será gerado com a mensagem “Uma operação assíncrona já está em andamento”.In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."
Exemplos
O exemplo a seguir obtém o valor do terceiro atributo.The following example gets the value of the third attribute.
reader.ReadToFollowing("book");
string isbn = reader.GetAttribute(2);
reader.ReadToFollowing("book")
Dim isbn As String = reader.GetAttribute(2)
Aplica-se a
GetAttribute(String)
public:
abstract System::String ^ GetAttribute(System::String ^ name);
public abstract string GetAttribute (string name);
public abstract string? GetAttribute (string name);
abstract member GetAttribute : string -> string
Public MustOverride Function GetAttribute (name As String) As String
Parâmetros
- name
- String
O nome qualificado do atributo.The qualified name of the attribute.
Retornos
O valor do atributo especificado.The value of the specified attribute. Se o atributo não foi encontrado ou o valor é String.Empty
, null
será retornado.If the attribute is not found or the value is String.Empty
, null
is returned.
Exceções
name
é null
.name
is null
.
Um método XmlReader foi chamado antes do término de uma operação assíncrona anterior.An XmlReader method was called before a previous asynchronous operation finished. Nesse caso, InvalidOperationException será gerado com a mensagem “Uma operação assíncrona já está em andamento”.In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."
Exemplos
O exemplo a seguir obtém o valor do atributo ISBN.The following example gets the value of the ISBN attribute.
reader.ReadToFollowing("book");
string isbn = reader.GetAttribute("ISBN");
Console.WriteLine("The ISBN value: " + isbn);
reader.ReadToFollowing("book")
Dim isbn As String = reader.GetAttribute("ISBN")
Console.WriteLine("The ISBN value: " + isbn)
Comentários
Esse método não move o leitor.This method does not move the reader.
Se o leitor estiver posicionado em um DocumentType
nó, esse método poderá ser usado para obter os literais públicos e do sistema, por exemplo, reader.GetAttribute("PUBLIC")
If the reader is positioned on a DocumentType
node, this method can be used to get the PUBLIC and SYSTEM literals, for example, reader.GetAttribute("PUBLIC")