fyntore.repopyop
fyntore.repopyop
CC#
Created by fyntore.repopyop on 3/5/2023 in #help
❔ Querying XML via LINQ
i have attached XML file for processing, which contain data from a electronics consumer store . I need to display Purchase Orders having the following criteria 1. Billing Address must be of state "PA" 2. Quantity > 2 3. Purchase orders must be dated between 2021 and 2022 I have used the following lambda Query to fetch data but it cannot access data in Quantity element therefore query returns empty data, how do i resolve the issue? var xdoc = XDocument.Load(@"E:\nitro\d1.xml"); var z = xdoc.Descendants("PurchaseOrders").Descendants("PurchaseOrder") .Where(e => DateTime.Parse(e.Attribute("OrderDate").Value).Year >= 2021 && ((DateTime.Parse(e.Attribute("OrderDate").Value).Year <= 2022))) .Descendants("Address").Where(a => a.Attribute("Type").Value == "Billing") .Descendants("Items").Descendants("Quantity").Where(q => Int32.Parse(q.Value) >= 2) .Select(x => x); foreach (var item in z) { Console.WriteLine(item); }
4 replies