XmlReader.MoveToAttribute Method (String)
[ 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 attribute with the specified Name.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- name
- Type: System.String
The qualified name of the attribute.
Return Value
Type: System.Booleantrue if the attribute is found; otherwise, false. If false, the reader's position does not change.
| Exception | Condition |
|---|---|
| NullReferenceException | The name value is null. |
After calling MoveToAttribute, the Name, NamespaceURI, and Prefix properties reflect the properties of that attribute.
StringBuilder output = new StringBuilder(); String xmlString = @"<root> <item sale-item='true' productID='123456' colors='blue green black'> <price>9.95</price> </item> <item sale-item='false' productID='124390'> <price>5.95</price> </item> <item sale-item='true' productID='53298'> <price>12.95</price> </item> </root>"; using (XmlReader reader = XmlReader.Create(new StringReader(xmlString))) { reader.ReadToDescendant("item"); do { reader.MoveToAttribute("sale-item"); Boolean onSale = reader.ReadContentAsBoolean(); if (onSale) { output.AppendLine(reader["productID"]); } } while (reader.ReadToNextSibling("item")); } OutputTextBlock.Text = output.ToString();
Show: