The System.Xml.XmlReader is a class in the System.Xml namespace of C# programming language used for reading XML documents. The XmlReader.MoveToElement() method returns a Boolean value indicating whether the reader is currently positioned on an element node.
Example 1:
XmlReader reader = XmlReader.Create("books.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "book") { if (reader.MoveToAttribute("isbn")) { Console.WriteLine("ISBN: " + reader.Value); } } }
In this example, the program reads an XML file named books.xml using an XmlReader instance. It iterates through the XML file, and when it reaches an element node named "book", it checks if it has an attribute named "isbn". If there is an attribute, it prints its value to the console.
In this example, the program reads an XML file named employees.xml using an XmlReader instance. It iterates through the XML file, and when it reaches an element node named "employee", it prints the value of its "name" attribute to the console.
Package library: System.Xml.
C# (CSharp) System.Xml XmlReader.MoveToElement - 56 examples found. These are the top rated real world C# (CSharp) examples of System.Xml.XmlReader.MoveToElement extracted from open source projects. You can rate examples to help us improve the quality of examples.