Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Is this possible with a LINQ to XML query???

Is this possible with a LINQ to XML query???

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqxmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 3 Offline
    3 Offline
    333mmm
    wrote on last edited by
    #1

    At the bottom I have pasted in an XML file I am working with.   My goal is to query this file using LINQ to XML and have the response formatted as follows: reportDate            alias24         alias39 2009-05-27         138,385.11      2,026.49 2009-05-28         138,535.98      2,233.74 2009-05-29         138,825.29      2,637.20 As you can see, I basically just want the total column for each account listed side by side. However, I'm not sure how to do this.   The closest I've been able to come is getting something that looks like this (with the 0 being the enumerated value given to the first alias and 1 being the enumerated value given to the second alias). 2009-05-27   0 2009-05-27   1 2009-05-28   0 2009-05-28   1 2009-05-29   0 2009-05-29   1 But I'm not sure how I would combine the rows for each date...and then have the total listed. Can any LINQ to XML gurus out there help? Here's the file... --------------------------> <FlexQueryResponse queryName="TestingXML" type="AF"> <Message>The following accounts were excluded from this statement: U69</Message> <FlexStatements count="0"> <FlexStatement accountId="U24" fromDate="20090501" toDate="20090529"> <AccountInformation acctAlias="alias24" accountId="U24" /> <EquitySummaryInBase> <EquitySummaryByReportDateInBase reportDate="2009-05-27" total="138,385.11" /> <EquitySummaryByReportDateInBase reportDate="2009-05-28" total="138,535.98" /> <EquitySummaryByReportDateInBase reportDate="2009-05-29" total="138,825.29" /> </EquitySummaryInBase> </FlexStatement><FlexStatement accountId="U39" fromDate="20090501" toDate="20090529"> <AccountInformation acctAlias="alias39" accountId="U39" /> <EquitySummaryInBase> <EquitySummaryByReportDateInBase reportDate="2009-05-27" total="2,026.49" /> <EquitySummaryByReportDateInBase reportDate="2009-05-28" total="2,233.74" /> <EquitySummaryByReportDateInBase reportDate="2009-05-29" total="2,637.20" /> </EquitySummaryInBase> </FlexStatement> </FlexStatements> </FlexQueryResponse>

    M 1 Reply Last reply
    0
    • 3 333mmm

      At the bottom I have pasted in an XML file I am working with.   My goal is to query this file using LINQ to XML and have the response formatted as follows: reportDate            alias24         alias39 2009-05-27         138,385.11      2,026.49 2009-05-28         138,535.98      2,233.74 2009-05-29         138,825.29      2,637.20 As you can see, I basically just want the total column for each account listed side by side. However, I'm not sure how to do this.   The closest I've been able to come is getting something that looks like this (with the 0 being the enumerated value given to the first alias and 1 being the enumerated value given to the second alias). 2009-05-27   0 2009-05-27   1 2009-05-28   0 2009-05-28   1 2009-05-29   0 2009-05-29   1 But I'm not sure how I would combine the rows for each date...and then have the total listed. Can any LINQ to XML gurus out there help? Here's the file... --------------------------> <FlexQueryResponse queryName="TestingXML" type="AF"> <Message>The following accounts were excluded from this statement: U69</Message> <FlexStatements count="0"> <FlexStatement accountId="U24" fromDate="20090501" toDate="20090529"> <AccountInformation acctAlias="alias24" accountId="U24" /> <EquitySummaryInBase> <EquitySummaryByReportDateInBase reportDate="2009-05-27" total="138,385.11" /> <EquitySummaryByReportDateInBase reportDate="2009-05-28" total="138,535.98" /> <EquitySummaryByReportDateInBase reportDate="2009-05-29" total="138,825.29" /> </EquitySummaryInBase> </FlexStatement><FlexStatement accountId="U39" fromDate="20090501" toDate="20090529"> <AccountInformation acctAlias="alias39" accountId="U39" /> <EquitySummaryInBase> <EquitySummaryByReportDateInBase reportDate="2009-05-27" total="2,026.49" /> <EquitySummaryByReportDateInBase reportDate="2009-05-28" total="2,233.74" /> <EquitySummaryByReportDateInBase reportDate="2009-05-29" total="2,637.20" /> </EquitySummaryInBase> </FlexStatement> </FlexStatements> </FlexQueryResponse>

      M Offline
      M Offline
      Mirko1980
      wrote on last edited by
      #2

      You should first make a query for getting all totals for each alias and date:

      var flatteningQuery = from statement in doc.Root.Element("FlexStatements").Descendants("FlexStatement")
      from summary in statement.Element("EquitySummaryInBase").Descendants("EquitySummaryByReportDateInBase")
      select new
      {
      Alias = statement.Element("AccountInformation").Attribute("acctAlias").Value,
      Date = summary.Attribute("reportDate").Value,
      Total = summary.Attribute("total").Value
      };

      Then, you can group the result from the previous query for each date, getting the list of all alias-total pair corresponding to report dates:

      var groupedQuery = from row in flatteningQuery
      group row by row.Date into dateGroup
      select new
      {
      Date = dateGroup.Key,
      Values = from item in dateGroup
      select new
      {
      Alias = item.Alias,
      Total = item.Total
      }
      };

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups