次の方法で共有


XPathNavigator.MoveToNextAttribute メソッド

次の属性に移動します。

Public MustOverride Function MoveToNextAttribute() As Boolean
[C#]
public abstract bool MoveToNextAttribute();
[C++]
public: virtual bool MoveToNextAttribute() = 0;
[JScript]
public abstract function MoveToNextAttribute() : Boolean;

戻り値

属性が正常に次の属性に移動する場合は true 。それ以上、属性が存在しない場合は false

解説

ナビゲータが現在属性に配置されていない場合、このメソッドは false を返し、ナビゲータの位置は変更されません。

ナビゲータが属性に配置されている場合、 MoveToNextMoveToPreviousMoveToFirst の各メソッドは適用できません。これらのメソッドは、常に false を返し、ナビゲータの位置を変更しません。

一度、属性に配置されたら、 MoveToParent を呼び出して、所有者要素に移動できます。

使用例

[Visual Basic, C#, C++] 各 book ノードのすべての属性を表示する例を次に示します

 
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath

public class Sample

  public shared sub Main()

    Dim doc as XPathDocument = new XPathDocument("books.xml")
    Dim nav as XPathNavigator = doc.CreateNavigator()
 
    ' Select all book nodes and display all attributes on each book.
    Dim ni as XPathNodeIterator = nav.SelectDescendants("book", "", false)
    while (ni.MoveNext())
       Dim nav2 as XPathNavigator = ni.Current.Clone()
       nav2.MoveToFirstAttribute()
       Console.WriteLine("{0} = {1}", nav2.Name, nav2.Value)
       while (nav2.MoveToNextAttribute())
          Console.WriteLine("{0} = {1}", nav2.Name, nav2.Value)
       end while
       Console.WriteLine() 
    end while

  end sub
end class

[C#] 
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;

public class Sample
{
  public static void Main()
  {
    XPathDocument doc = new XPathDocument("books.xml");
    XPathNavigator nav = doc.CreateNavigator();
 
    // Select all book nodes and display all attributes on each book.
    XPathNodeIterator ni = nav.SelectDescendants("book", "", false);
    while (ni.MoveNext()){
       XPathNavigator nav2 = ni.Current.Clone();
       nav2.MoveToFirstAttribute();
       Console.WriteLine("{0} = {1}", nav2.Name, nav2.Value);
       while (nav2.MoveToNextAttribute()){
          Console.WriteLine("{0} = {1}", nav2.Name, nav2.Value);
       }
       Console.WriteLine(); 
    } 

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::XPath;

int main() {
   XPathDocument* doc = new XPathDocument(S"books.xml");
   XPathNavigator * nav = doc -> CreateNavigator();

   // Select all book nodes and display all attributes on each book.
   XPathNodeIterator * ni = nav -> SelectDescendants(S"book", S"", false);
   while (ni -> MoveNext())
   {
      XPathNavigator * nav2 = ni -> Current -> Clone();
      nav2 -> MoveToFirstAttribute();
      Console::WriteLine(S" {0} = {1}", nav2 -> Name, nav2 -> Value);
      while (nav2 -> MoveToNextAttribute()) 
      {
         Console::WriteLine(S" {0} = {1}", nav2 -> Name, nav2 -> Value);
      }
      Console::WriteLine(); 
   } 
}

[Visual Basic, C#, C++] この例では、入力として、 books.xml というファイルを使用しています。

<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
  <book genre="autobiography" publicationdate="1981" 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" 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" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

XPathNavigator クラス | XPathNavigator メンバ | System.Xml.XPath 名前空間 | MoveToFirstAttribute | MoveToAttribute | GetAttribute | HasAttributes