public static List <Ledgers> LoadLedgers() { List <Ledgers> ListLedgerRecords = new List <Ledgers>(); // Execute the query using the LINQ to XML XDocument doc = XDocument.Load(@"Ledgers.xml"); var records = from r in doc.Element("Ledgers").Elements("Ledger") select r; foreach (var record in records) { Ledgers lLedger = new Ledgers { Id = record.Attribute("Id").Value, Name = record.Element("Name").Value, PhoneNo = record.Element("PhoneNo").Value, Email = record.Element("Email").Value, PanNo = record.Element("PanNo").Value, SaleTaxNo = record.Element("SaleTaxNo").Value, TinNo = record.Element("TinNo").Value }; ListLedgerRecords.Add(lLedger); } return(ListLedgerRecords); }
public static Ledgers LoadLedger(string ledgerName) { XDocument doc = XDocument.Load(@"Ledgers.xml"); var records = from r in doc.Element("Ledgers").Elements("Ledger") where r.Element("Name").Value == ledgerName select r; Ledgers ld = new Ledgers(); foreach (var record in records) { Ledgers lLedger = new Ledgers { Id = record.Attribute("Id").Value, Name = record.Element("Name").Value, PhoneNo = record.Element("PhoneNo").Value, Email = record.Element("Email").Value, PanNo = record.Element("PanNo").Value, SaleTaxNo = record.Element("SaleTaxNo").Value, TinNo = record.Element("TinNo").Value }; ld = lLedger; } return(ld); }