XmlValidatingReader.GetAttribute メソッド

定義

属性の値を取得します。

オーバーロード

GetAttribute(Int32)

指定したインデックスの属性の値を取得します。

GetAttribute(String)

指定した名前の属性の値を取得します。

GetAttribute(String, String)

指定したローカル名および名前空間 URI (Uniform Resource Identifier) の属性値を取得します。

GetAttribute(Int32)

指定したインデックスの属性の値を取得します。

public:
 override System::String ^ GetAttribute(int i);
public override string GetAttribute (int i);
override this.GetAttribute : int -> string
Public Overrides Function GetAttribute (i As Integer) As String

パラメーター

i
Int32

属性のインデックス。 インデックスの値は、0 から始まります。 最初の属性のインデックスは 0 です。

戻り値

String

指定した属性の値。

例外

i パラメーターが 0 未満か、AttributeCount 以上です。

注釈

このメソッドは、リーダーを移動しません。

注意

このクラスはXmlValidatingReader、.NET Framework 2.0 では廃止されています。 クラスとメソッドを使用してXmlReaderSettings、検証XmlReaderインスタンスをCreate作成できます。 詳細については、XmlReader のリファレンス ページの「解説」を参照してください。

こちらもご覧ください

適用対象

GetAttribute(String)

指定した名前の属性の値を取得します。

public:
 override System::String ^ GetAttribute(System::String ^ name);
public override string? GetAttribute (string name);
public override string GetAttribute (string name);
override this.GetAttribute : string -> string
Public Overrides Function GetAttribute (name As String) As String

パラメーター

name
String

属性の限定名。

戻り値

String

指定した属性の値。 指定した属性が見つからない場合は null が返されます。

次の例では、ISBN 属性の値を取得します。

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the validating reader.
   XmlTextReader^ txtreader = gcnew XmlTextReader( "attrs.xml" );
   XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
   
   //Read the ISBN attribute.
   reader->MoveToContent();
   String^ isbn = reader->GetAttribute( "ISBN" );
   Console::WriteLine( "The ISBN value: {0}", isbn );
   
   //Close the reader.
   reader->Close();
}

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    //Create the validating reader.
    XmlTextReader txtreader = new XmlTextReader("attrs.xml");
    XmlValidatingReader reader = new XmlValidatingReader(txtreader);

    //Read the ISBN attribute.
    reader.MoveToContent();
    string isbn = reader.GetAttribute("ISBN");
    Console.WriteLine("The ISBN value: " + isbn);

    //Close the reader.
    reader.Close();
  }
} // End class
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main()

    'Create the validating reader.
    Dim txtreader as XmlTextReader = new XmlTextReader("attrs.xml")
    Dim reader as XmlValidatingReader = new XmlValidatingReader(txtreader)

    'Read the ISBN attribute.
    reader.MoveToContent()
    Dim isbn as string = reader.GetAttribute("ISBN")
    Console.WriteLine("The ISBN value: " + isbn)

    'Close the reader.
    reader.Close()

  End sub
End class 

この例では、 attrs.xmlファイルを入力として使用します。

<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>

注釈

注意

このクラスはXmlValidatingReader、.NET Framework 2.0 では廃止されています。 クラスとメソッドを使用してXmlReaderSettings、検証XmlReaderインスタンスをCreate作成できます。 詳細については、XmlReader のリファレンス ページの「解説」を参照してください。

このメソッドは、リーダーを移動しません。

リーダーがノード上に DocumentType 配置されている場合、このメソッドを使用して PUBLIC リテラルと SYSTEM リテラルを取得できます。たとえば、 reader.GetAttribute("PUBLIC")

こちらもご覧ください

適用対象

GetAttribute(String, String)

指定したローカル名および名前空間 URI (Uniform Resource Identifier) の属性値を取得します。

public:
 override System::String ^ GetAttribute(System::String ^ localName, System::String ^ namespaceURI);
public override string? GetAttribute (string localName, string? namespaceURI);
public override string GetAttribute (string localName, string namespaceURI);
override this.GetAttribute : string * string -> string
Public Overrides Function GetAttribute (localName As String, namespaceURI As String) As String

パラメーター

localName
String

属性のローカル名。

namespaceURI
String

属性の名前空間 URI。

戻り値

String

指定した属性の値。 指定した属性が見つからない場合は null が返されます。 このメソッドは、リーダーを移動しません。

注釈

注意

このクラスはXmlValidatingReader、.NET Framework 2.0 では廃止されています。 クラスとメソッドを使用してXmlReaderSettings、検証XmlReaderインスタンスをCreate作成できます。 詳細については、XmlReader のリファレンス ページの「解説」を参照してください。

次の XML には、特定の名前空間の属性が含まれています。

<test xmlns:dt="urn:datatypes" dt:type="int"/>  

属性を dt:type 検索するには、1 つの引数 (プレフィックスとローカル名) または 2 つの引数 (ローカル名と名前空間 URI) を使用します。

String dt = reader.GetAttribute("dt:type");  
String dt2 = reader.GetAttribute("type","urn:datatypes");  

属性を xmlns:dt 検索するには、次のいずれかの引数を使用します。

String dt3 = reader.GetAttribute("xmlns:dt");  
String dt4 = reader.GetAttribute("dt",http://www.w3.org/2000/xmlns/);  

この情報は、プロパティを使用して Prefix 取得することもできます。

こちらもご覧ください

適用対象