Mega Code Archive

 
Categories / C# / XML
 

XmlReader GetAttribute (String) returns the attribute with the specified Name

using System; using System.IO; using System.Xml; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){         XmlDocument doc = new XmlDocument();         doc.Load("books.xml");         XmlNodeReader nodeReader = new XmlNodeReader(doc);                  XmlReaderSettings settings = new XmlReaderSettings();         settings.ValidationType = ValidationType.Schema;         settings.Schemas.Add("urn:bookstore-schema", "books.xsd");                  XmlReader reader = XmlReader.Create(nodeReader, settings);         while (reader.Read()){             reader.ReadToFollowing("book");             string isbn = reader.GetAttribute("ISBN");             Console.WriteLine("The ISBN value: " + isbn);         }     } }