XPathNavigator.MoveToFirstAttribute メソッド
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XPathNavigator Dim returnValue As Boolean returnValue = instance.MoveToFirstAttribute
XPathNavigator が現在のノードの最初の属性に正常に移動された場合は true を返します。それ以外の場合は false を返します。false の場合、XPathNavigator の位置は変更されません。

XPathNavigator が要素に現在配置されていない場合、このメソッドは false を返し、XPathNavigator の位置は変更されません。
MoveToFirstAttribute が正常に呼び出されると、LocalName、NamespaceURI、Prefix の各プロパティは、この属性の値を反映します。XPathNavigator が属性に配置されている場合、MoveToNext、MoveToPrevious、MoveToFirst の各メソッドは適用できません。これらのメソッドは、常に false を返し、XPathNavigator の位置を変更しません。代わりに、MoveToNextAttribute を呼び出して、次の属性ノードに移動できます。

MoveToFirstAttribute メソッドと MoveToNextAttribute メソッドを使用して、books.xml ファイル内にある各 book のすべての属性を表示する例を次に示します。
Dim document As XPathDocument = New XPathDocument("books.xml") Dim navigator As XPathNavigator = document.CreateNavigator() ' Select all book nodes and display all attributes on each book. Dim nodes As XPathNodeIterator = navigator.SelectDescendants("book", "", False) While nodes.MoveNext() Dim navigator2 As XPathNavigator = nodes.Current.Clone() navigator2.MoveToFirstAttribute() Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value) While navigator2.MoveToNextAttribute() Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value) End While Console.WriteLine() End While
XPathDocument document = new XPathDocument("books.xml"); XPathNavigator navigator = document.CreateNavigator(); // Select all book nodes and display all attributes on each book. XPathNodeIterator nodes = navigator.SelectDescendants("book", "", false); while (nodes.MoveNext()) { XPathNavigator navigator2 = nodes.Current.Clone(); navigator2.MoveToFirstAttribute(); Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value); while (navigator2.MoveToNextAttribute()) { Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value); } Console.WriteLine(); }
この例では、入力として、books.xml というファイルを使用しています。
<bookstore> <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore>

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からXPathNavigator.MoveToFirstAttribute メソッドを検索する場合は、下記のリンクをクリックしてください。

- XPathNavigator.MoveToFirstAttribute メソッドのページへのリンク