Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:06:58+00:00 2026-05-28T17:06:58+00:00

I’m working with an xml document in C# that has multiple (100+) points of

  • 0

I’m working with an xml document in C# that has multiple (100+) points of stock market data. I’d like to create objects and add them to a List<> by passing initialization values retrieved from an xml document via linq. At the moment I’m just able to run a linq query and return one of the xml fields, in the code below, the attribute “symbol.” I’d also like to return the document’s “LastTradeDate, DaysLow, DaysHigh, LastTradePriceOnly, Open, and Volume.” From there, my custom constructor is: StockDataPoint(Symbol, TradeDate, Open, High, Low, Close, Volume). A nudge in the right direction would be great. Here’s the current linq:

var makeInfo =
      from s in doc.Descendants("quote")
      where s.Element("LastTradeDate") != null
      && s.Attribute("symbol") != null
      let dateStr = s.Element("LastTradeDate").Value
      where !string.IsNullOrEmpty(dateStr)
      && DateTime.Parse(dateStr, enUS) == targetDate
      select s.Attribute("symbol").Value;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:06:59+00:00Added an answer on May 28, 2026 at 5:06 pm

    Well it depends on your XML format, but you might just want something like:

    ...
    select new StockDataPoint((string) s.Attribute("symbol"),
                              (DateTime) s.Attribute("TradeDate"),
                              (decimal) s.Attribute("Open"),
                              (decimal) s.Attribute("High"),
                              (decimal) s.Attribute("Low"),
                              (decimal) s.Attribute("Close"),
                              (long) s.Attribute("Volume"));
    

    Note that by use the explicit operators on XAttribute, you can avoid performing the parse yourself. Indeed, you can use this earlier in your query too:

    var makeInfo = from s in doc.Descendants("quote")
                   where s.Attribute("symbol") &&
                         (DateTime?) s.Attribute("LastTradeDate") == targetDate
                   select ...
    

    If the target of the cast is a nullable type (either a nullable value type or a reference type) then if the attribute is missing, the result will be the null value for that type, which is very handy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.