Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to read data from a xml file based on some condition in C#?

Please Suggest Me.....
Posted

Hi
To read data from xml file I would first serialize the xml to a strongly typed object.

Check this

From-XML-to-Strong-Types-in-C


Basically using a class you can serialize the xml file to an object and then use this as normal in your c#.

Does this help?
 
Share this answer
 
You didn't mention based on what condition you want to read data but
Using linq you can do this.

Check these link it may help you.


http://stackoverflow.com/questions/15499082/linq-to-xml-fetching-value-based-on-condition[^]

http://www.c-sharpcorner.com/UploadFile/54db21/select-data-from-xml-with-where-clause-using-linq-to-xml/[^]
 
Share this answer
 
You can also use the classes XDocument, XElement, XAttribute etc. in LINQ.
This approach is not strongly typed, but you have to read the structure manually.

System.Xml.Linq Namespace[^]

Small example:
C#
XDocument xd = new XDocument();
xd.Load(@"SomeFile.xml");

// Get the first element with the name 'SomeNode'
XElement xe = xd.Element("SomeNode");
etc.


This is a good alternative to XSD if you only want to read the data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900