XmlElement.HasAttribute Método
Definição
Determina se o nó atual tem o atributo especificado.Determines whether the current node has the specified attribute.
Sobrecargas
| HasAttribute(String) |
Determina se o nó atual tem um atributo com o nome especificado.Determines whether the current node has an attribute with the specified name. |
| HasAttribute(String, String) |
Determina se o nó atual tem um atributo com o nome do local especificado e o URI de namespace.Determines whether the current node has an attribute with the specified local name and namespace URI. |
HasAttribute(String)
Determina se o nó atual tem um atributo com o nome especificado.Determines whether the current node has an attribute with the specified name.
public:
virtual bool HasAttribute(System::String ^ name);
public virtual bool HasAttribute (string name);
abstract member HasAttribute : string -> bool
override this.HasAttribute : string -> bool
Public Overridable Function HasAttribute (name As String) As Boolean
Parâmetros
- name
- String
O nome do atributo a ser localizado.The name of the attribute to find. Este é um nome qualificado.This is a qualified name. Ele é comparado com a propriedade Name do nó correspondente.It is matched against the Name property of the matching node.
Retornos
true se o nó atual tiver o atributo especificado; caso contrário, false.true if the current node has the specified attribute; otherwise, false.
Exemplos
O exemplo a seguir verifica se o elemento tem o atributo especificado.The following example checks to see if the element has the specified attribute.
#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>" );
XmlElement^ root = doc->DocumentElement;
// Check to see if the element has a genre attribute.
if ( root->HasAttribute( "genre" ) )
{
String^ genre = root->GetAttribute( "genre" );
Console::WriteLine( genre );
}
}
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>");
XmlElement root = doc.DocumentElement;
// Check to see if the element has a genre attribute.
if (root.HasAttribute("genre")){
String genre = root.GetAttribute("genre");
Console.WriteLine(genre);
}
}
}
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>")
Dim root as XmlElement = doc.DocumentElement
' Check to see if the element has a genre attribute.
if (root.HasAttribute("genre"))
Dim genre as String = root.GetAttribute("genre")
Console.WriteLine(genre)
end if
Console.WriteLine("Display the modified XML...")
Console.WriteLine(doc.InnerXml)
end sub
end class
Aplica-se a
HasAttribute(String, String)
Determina se o nó atual tem um atributo com o nome do local especificado e o URI de namespace.Determines whether the current node has an attribute with the specified local name and namespace URI.
public:
virtual bool HasAttribute(System::String ^ localName, System::String ^ namespaceURI);
public virtual bool HasAttribute (string localName, string namespaceURI);
public virtual bool HasAttribute (string localName, string? namespaceURI);
abstract member HasAttribute : string * string -> bool
override this.HasAttribute : string * string -> bool
Public Overridable Function HasAttribute (localName As String, namespaceURI As String) As Boolean
Parâmetros
- localName
- String
O nome local do atributo a ser localizado.The local name of the attribute to find.
- namespaceURI
- String
O URI do namespace do atributo a ser localizado.The namespace URI of the attribute to find.
Retornos
true se o nó atual tiver o atributo especificado; caso contrário, false.true if the current node has the specified attribute; otherwise, false.