Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MoveToNextAttribute Method

XPathNavigator.MoveToNextAttribute Method

When overridden in a derived class, moves the XPathNavigator to the next attribute.

Namespace: System.Xml.XPath
Assembly: System.Xml (in system.xml.dll)

public abstract bool MoveToNextAttribute ()
public abstract boolean MoveToNextAttribute ()
public abstract function MoveToNextAttribute () : boolean
Not applicable.

Return Value

Returns true if the XPathNavigator is successful moving to the next attribute; false if there are no more attributes. If false, the position of the XPathNavigator is unchanged.

If the XPathNavigator is not currently positioned on an attribute, this method returns false and the position of the XPathNavigator does not change.

When the XPathNavigator is positioned on an attribute, the methods MoveToNext, MoveToPrevious, and MoveToFirst methods are not applicable. These methods always return false and do not change the position of the XPathNavigator.

After the XPathNavigator is positioned on an attribute, you can call MoveToParent to move to the owner element.

The following example uses the MoveToFirstAttribute and MoveToNextAttribute methods to display all the attributes for each book in the books.xml file.

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();
}

The example takes the books.xml file as an input.

<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 Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft