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 947901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:09:20+00:00 2026-05-15T23:09:20+00:00

I’m looking for advice here on a smart solution to my problem. I’m writing

  • 0

I’m looking for advice here on a smart solution to my problem.

I’m writing an XML Document using the XMLWriter class and reading data out of an ADO.NET DataReader in a forward-only fashion. In the top of my XML file I need to have elements like so:

<datefrom>2010-07-08</datefrom>
<dateto>2010-07-10</dateto>
<total>335.00</total>

<datefrom> needs to be the earliest date found in the data.
<dateto> is the latest date.
<total> is the sum of all <totalpaid>115.00</totalpaid> elements listed later in the document.

As I create/write the XML elements to the file I can keep track of the earlier/latest dates and I can keep summing together all the <totalpaid> amounts to get a total.

But…

Once I’ve reached the end of my DataReader, how would you recommend getting those values into the elements at the top of the XML file? Should I put replacement tokens as the values between the opening and closing tags (i.e. @datefrom, @dateto, @total) and replace them somehow? Is that possible? Should I write & close the file, re-open it and replace the tokens with the actual values? Is there some way to replace the tokens with the values before writing the XML to the file? I haven’t worked much with generating XML files so I don’t know if there’s some standard way to go about doing this.

Thanks!

  • 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-15T23:09:21+00:00Added an answer on May 15, 2026 at 11:09 pm

    A XmlWriter is forward-only so you cannot insert elements in the beginning of the document. One possibility is to perform two SQL queries to your database. The first one will aggregate data and return you the three values which you write in the beginning, then you perform your second query to write the rest. This way the aggregation (min, max, total) is done at the database level and you don’t need to calculate them in your code.

    If you can’t do this you could use a XDocument which will allow you inserting nodes anywhere but it has the whole document in memory which may not be acceptable if the document is big.

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

Sidebar

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.