XmlReader.MoveToElement 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 element that contains the current attribute node.
Assembly: System.Xml (in System.Xml.dll)
Return Value
Type: System.Booleantrue if the reader is positioned on an attribute (the reader moves to the element that owns the attribute); false if the reader is not positioned on an attribute (the position of the reader does not change).
StringBuilder output = new StringBuilder(); String xmlString = @"<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> </bookstore>"; // Create an XmlReader using (XmlReader reader = XmlReader.Create(new StringReader(xmlString))) { reader.ReadToFollowing("book"); if (reader.HasAttributes) { output.Append("Attributes of <" + reader.Name + ">"); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); output.Append(" " + reader.Name + "=" + reader.Value); } reader.MoveToElement(); // Moves the reader back to the element node. } } OutputTextBlock.Text = output.ToString();
Show: