Monday, July 6, 2009

XmlTextReader.GetAttribute Method (String)

C#
using System;

using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
XmlTextReader reader = null;

try

{
//Load the reader with the XML file.
reader = new XmlTextReader("attrs.xml");

//Read the ISBN attribute.
reader.MoveToContent();
string isbn = reader.GetAttribute("ISBN");
Console.WriteLine("The ISBN value: " + isbn);

}
finally
{
if (reader != null)
reader.Close();
}
}

} // End class


The example uses the file, attrs.xml, as input.

<book genre='novel' ISBN='1-861003-78' pubdate='1987'>

</book>

ref : http://msdn.microsoft.com/en-us/library/3c932kx5.aspx

No comments:

Counter