<?xml version="1.0" encoding="utf-8" ?> <customers> <customer name="steven"> <id>011475</id> <fname>steven</fname> <age>36</age> <city>newyork</city> </customer> <customer name="julian"> <id>52485</id> <fname>julian</fname> <age>22</age> <city>london</city> </customer> <customer name="dev"> <id>5485</id> <fname>dev</fname> <age>26</age> <city>sydny</city> </customer> <customer name="ben"> <id>485214</id> <fname>ben</fname> <age>36</age> <city>sydny</city> </customer> <customer name="john"> <id>24586</id> <fname>John</fname> <age>42</age> <city>london</city> </customer> </customers>
XDocument xdoc = XDocument.Load("D:\\customers.xml");
// list box binding var customes = from customer in xdoc.Descendants("customers").Elements("customer").Attributes("name") select customer.Value; cmbCustomer.DataSource = customes.ToList(); // Grid binding var customesList = from customers in xdoc.Root.Elements() name = customers.Element("fname").Value, id = customers.Element("id").Value, age = customers.Element("age").Value, city = customers.Element("city").Value }; grdCustomer.DataSource = customesList.ToList();
var whereList = from customers in xdoc.Root.Elements() where customers.Element("city").Value == "london" select new { name = customers.Element("fname").Value, city = customers.Element("city").Value }; grdWhere.DataSource = whereList.ToList();
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.