المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Read XML Data from C#



C# Programming
05-27-2009, 12:52 PM
hi

i need to read XML data from an XML file into C#.i tried using XmlTextReader class but i am not getting all elements.

My XML file is as follows



username




My code is as follows

// Create an instance of XmlTextReader and call Read method to read the file

XmlTextReader textReader = new XmlTextReader("C:\\books.xml");

textReader.Read();

// If the node has value

while (textReader.Read())

{

// Move to fist element

textReader.MoveToElement();


Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
}

in the above code i am not getting all the nodes and elements...(maybe due to whitespaces)

please give links to any code samples etc...is there any other method to read??

thanks in advance...

"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"