MoveToNextAttribute Method
TOC
Collapse the table of content
Expand the table of content

XmlReader.MoveToNextAttribute Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public abstract bool MoveToNextAttribute()

Return Value

Type: System.Boolean
true if there is a next attribute; false if there are no more attributes.

If the current node is an element node, this method is equivalent to MoveToFirstAttribute. If MoveToNextAttribute returns true, the reader moves to the next attribute; otherwise, the position of the reader does not change.



StringBuilder output = new StringBuilder();

String xmlString =
    @"<bookstore>
  <book genre='novel' ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
    <price>19.95</price>
  </book>
  <book genre='novel' ISBN='1-861001-57-5'>
    <title>Pride And Prejudice</title>
    <price>24.95</price>
  </book>
</bookstore>";

// Load the file and ignore all white space.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), settings))
{
    // Move the reader to the second book node.
    reader.MoveToContent();
    reader.ReadToDescendant("book");
    reader.Skip(); //Skip the first book.

    // Parse the file starting with the second book node.
    do
    {
        switch (reader.NodeType)
        {
            case XmlNodeType.Element:
                output.AppendLine("<" + reader.Name);
                while (reader.MoveToNextAttribute())
                {
                    output.AppendLine(" " + reader.Name + "=" + reader.Value);
                }
                output.AppendLine(">");
                break;
            case XmlNodeType.Text:
                output.AppendLine(reader.Value);
                break;
            case XmlNodeType.EndElement:
                output.AppendLine("</" + reader.Name + ">");
                break;
        }
    } while (reader.Read());
}

OutputTextBlock.Text = output.ToString();


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft