<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE Report SYSTEM "https://abc.mycompany.com/abc/processingreports/processeddtd/abcd_1_8.dtd"> <Report Name="Daily TRANSACTIONS" Version="1.8" xmlns="https://abc.mycompany.com/abc/processingreports/processeddtd/abcd_1_8.dtd" OrgID="ABC_PQR" StartDate="2011-03-10T00:00:00+00:00" EndDate="2011-03-11T00:00:00+00:00"> <Requests> <Request ID="2" Date="2011-03-10T00:21:14+00:00" OrderNumber="1"> <BillTo> <FirstName /> </BillTo> <LineItems> <LineItem Number="0"> <Quantity /> </LineItem> </LineItems> </Request> <Request ID="2" Date="2011-03-10T00:21:14+00:00" OrderNumber="1"> TransactionNumber="389958330911111"> <BillTo> <FirstName>A</FirstName> </BillTo> <LineItems> <LineItem Number="0"> <Quantity>1</Quantity> </LineItem> </LineItems> <UniqueData> <UniqueNumber>11111111111111111111111111111</UniqueNumber> </UniqueData></Request></Requests></Report> In above XML file using Linq i just want to extract OrderNumber and UniqueNumber OrderNumber="1" 11111111111111111111111111111
Any ideas, suggestions to extract these details?
I can select elements from above xml file but UniqueNumber is not associated with OrderNumber
I am looking for something below (ignore lines where UniqueNumber is not present) OrderNumber - assosicated UniqueNumber
Update In "requiredElements" i am expecting two coulmns OrderNumber and UniqueNumber and holding associated values with each other as 1 and 11111 and so one
#region FileOpen with UTF8 Encoding TextReader sr = new StreamReader(cFileName, Encoding.UTF8); XDocument reportfile = XDocument.Load(sr, LoadOptions.SetBaseUri); XElement xd = XElement.Parse(reportfile.ToString()); sr.Close(); #endregion XNamespace ns = xd.Attribute("xmlns").Value; var requiredElements = (from resultquery in reportfile.Descendants() select new { OrderNumber = resultquery.Attribute("OrderNumber"), UniqueNumber= (string)resultquery.Element(AddNameSpace(ns, "UniqueNumber")), } );