XmlElement.HasAttribute メソッド

定義

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

オーバーロード

名前 説明
HasAttribute(String)

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

HasAttribute(String, String)

現在のノードに、指定したローカル名と名前空間 URI を持つ属性があるかどうかを判断します。

HasAttribute(String)

ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
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;
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)

ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
XmlElement.cs
ソース:
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

適用対象