XmlNodeReader.MoveToAttribute メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した属性に移動します。
オーバーロード
| 名前 | 説明 |
|---|---|
| MoveToAttribute(Int32) |
指定したインデックスを持つ属性に移動します。 |
| MoveToAttribute(String) |
指定した名前の属性に移動します。 |
| MoveToAttribute(String, String) |
指定したローカル名と名前空間 URI を持つ属性に移動します。 |
MoveToAttribute(Int32)
指定したインデックスを持つ属性に移動します。
public:
override void MoveToAttribute(int attributeIndex);
public override void MoveToAttribute(int attributeIndex);
override this.MoveToAttribute : int -> unit
Public Overrides Sub MoveToAttribute (attributeIndex As Integer)
パラメーター
- attributeIndex
- Int32
属性のインデックス。
例外
i パラメーターが 0 未満か、AttributeCount以上です。
例
次の例では、ルート ノード上のすべての属性を読み取ります。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlNodeReader reader = null;
try
{
//Create and load the XML document.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " +
"</book>");
//Load the XmlNodeReader
reader = new XmlNodeReader(doc);
//Read the attributes on the root element.
reader.MoveToContent();
if (reader.HasAttributes){
for (int i=0; i<reader.AttributeCount; i++){
reader.MoveToAttribute(i);
Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
}
//Return the reader to the book element.
reader.MoveToElement();
}
}
finally
{
if (reader != null)
reader.Close();
}
}
} // End class
Option Strict
Option Explicit
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlNodeReader = Nothing
Try
'Create and load the XML document.
Dim doc As New XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " & _
"</book>")
'Load the XmlNodeReader
reader = New XmlNodeReader(doc)
'Read the attributes on the root element.
reader.MoveToContent()
If reader.HasAttributes Then
Dim i As Integer
For i = 0 To reader.AttributeCount - 1
reader.MoveToAttribute(i)
Console.WriteLine("{0} = {1}", reader.Name, reader.Value)
Next i
'Return the reader to the book element.
reader.MoveToElement()
End If
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
注釈
Note
新しい機能を利用するには、XmlReader クラスと XmlReaderSettings メソッドを使用してCreate インスタンスを作成することをお勧めします。 詳細については、「 XmlReader リファレンス」ページの「解説」セクションを参照してください。
適用対象
MoveToAttribute(String)
指定した名前の属性に移動します。
public:
override bool MoveToAttribute(System::String ^ name);
public override bool MoveToAttribute(string name);
override this.MoveToAttribute : string -> bool
Public Overrides Function MoveToAttribute (name As String) As Boolean
パラメーター
- name
- String
属性の修飾名。
返品
true 属性が見つかった場合。それ以外の場合は false。
false場合、リーダーの位置は変更されません。
注釈
Note
新しい機能を利用するには、XmlReader クラスと XmlReaderSettings メソッドを使用してCreate インスタンスを作成することをお勧めします。 詳細については、「 XmlReader リファレンス」ページの「解説」セクションを参照してください。
このメソッドを呼び出した後、 Name、 NamespaceURI、および Prefix のプロパティには、その属性のプロパティが反映されます。
適用対象
MoveToAttribute(String, String)
指定したローカル名と名前空間 URI を持つ属性に移動します。
public:
override bool MoveToAttribute(System::String ^ name, System::String ^ namespaceURI);
public override bool MoveToAttribute(string name, string namespaceURI);
override this.MoveToAttribute : string * string -> bool
Public Overrides Function MoveToAttribute (name As String, namespaceURI As String) As Boolean
パラメーター
- name
- String
属性のローカル名。
- namespaceURI
- String
属性の名前空間 URI。
返品
true 属性が見つかった場合。それ以外の場合は false。
false場合、リーダーの位置は変更されません。
注釈
Note
新しい機能を利用するには、XmlReader クラスと XmlReaderSettings メソッドを使用してCreate インスタンスを作成することをお勧めします。 詳細については、「 XmlReader リファレンス」ページの「解説」セクションを参照してください。
このメソッドを呼び出した後、 Name、 NamespaceURI、および Prefix のプロパティには、その属性のプロパティが反映されます。