XmlElement.HasAttribute メソッド

定義

現在のノードに指定した属性があるかどうかを確認します。

オーバーロード

HasAttribute(String)

現在のノードに指定した名前の属性があるかどうかを判断します。

HasAttribute(String, String)

指定したローカル名および名前空間 URI の属性が現在のノードにあるかどうかを確認します。

HasAttribute(String)

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

現在のノードに指定した名前の属性があるかどうかを判断します。

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

パラメーター

name
String

検索対象の属性名です。 これは修飾名です。 一致するノードの Name プロパティに一致します。

戻り値

現在のノードに指定した属性がある場合は true。それ以外の場合は false

次の例では、 要素に指定された属性があるかどうかを確認します。

#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

適用対象

HasAttribute(String, String)

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

指定したローカル名および名前空間 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

パラメーター

localName
String

検索する属性のローカル名。

namespaceURI
String

検索する属性の名前空間 URI。

戻り値

現在のノードに指定した属性がある場合は true。それ以外の場合は false

適用対象