XmlElement.HasAttribute Metodo

Definizione

Determina se il nodo corrente dispone dell'attributo specificato.

Overload

HasAttribute(String)

Determina se il nodo corrente dispone di un attributo con il nome specificato.

HasAttribute(String, String)

Determina se il nodo corrente dispone di un attributo con il nome locale e l'URI dello spazio dei nomi specificati.

HasAttribute(String)

Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

Determina se il nodo corrente dispone di un attributo con il nome specificato.

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

Parametri

name
String

Nome dell'attributo da trovare. Si tratta di un nome completo. Viene confrontato con la proprietà Name del nodo corrispondente.

Restituisce

true se il nodo corrente dispone dell'attributo specificato. In caso contrario, false.

Esempio

Nell'esempio seguente viene verificato se l'elemento ha l'attributo specificato.

#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

Si applica a

HasAttribute(String, String)

Source:
XmlElement.cs
Source:
XmlElement.cs
Source:
XmlElement.cs

Determina se il nodo corrente dispone di un attributo con il nome locale e l'URI dello spazio dei nomi specificati.

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

Parametri

localName
String

Nome locale dell'attributo da individuare.

namespaceURI
String

URI dello spazio dei nomi dell'attributo da individuare.

Restituisce

true se il nodo corrente dispone dell'attributo specificato. In caso contrario, false.

Si applica a