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

  • Home
  • SEARCH
  • 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 8130693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:49:07+00:00 2026-06-06T08:49:07+00:00

I have a very hard-coded XML reader below: using System; using System.Collections.Generic; using System.Linq;

  • 0

I have a very hard-coded XML reader below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Diagnostics;

namespace XML
{
    class Program
    {
        static void Main(string[] args)
        {
        // XML text reader stuff
            XmlTextReader textReader = new XmlTextReader("H:\\User\\Desktop\\secLendingXML.cfm.xml");
        //string[] Fed_Array = new string[] {"Actual Available to Borrow", "Outstanding Loans",
        //"Par Submitted", "Par Accepted", "WTD Average Rate"};
        int j = 0;
    // Trace listener stuff.
        Stream myFile = File.Create("H:\\User\\Desktop\\Fed_Sec_Lending.txt");
        TextWriterTraceListener myTextListener = new TextWriterTraceListener(myFile);
        Trace.Listeners.Add(myTextListener);
        while (textReader.Read())
        {
            switch (textReader.NodeType)
            {
                case XmlNodeType.Element:
                    for (int i = 0; i < textReader.AttributeCount; i++)
                    {
                        textReader.MoveToAttribute(i);
                        switch (textReader.Name)
                        {
                            case "securityMaturityDate": 
                                Trace.Write(textReader.Value + ",");
                                Console.Write(textReader.Value + ",");
                                break;
                            case "couponRate":
                                Trace.Write(textReader.Value + ",");
                                Console.Write(textReader.Value + ",");
                                break;
                            case "securityType":
                                Trace.Write(textReader.Value + ",");
                                Console.Write(textReader.Value + ",");
                                j = 0;
                                break;
                            case "value":
                                Trace.Write(textReader.Value + ",");
                                Console.Write(textReader.Value + ",");
                                j = j + 1;
                                if (j > 4)
                                {
                                    Trace.Write(Environment.NewLine);
                                    Console.Write(Environment.NewLine);
                                }
                                break;

                            }
                        }
                        break;
                }
            }
        }
    }
}

It seems to be working fine for the most part in reading this XML page from my desktop. However, the Trace writer does not seem to be writing the same data as the console output. I have a snapshot of the console output here, and the bottom of the text file that the Trace is writing to here, and as you can see, the last few rows don’t match up.

For whatever reason, the text file is not receiving the same output as the console, even though they should be. Is there a reason anyone can see as to why the text file is being cut short here?

  • 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-06-06T08:49:08+00:00Added an answer on June 6, 2026 at 8:49 am

    I was able to answer the question by replacing the Trace writer with a Streamwriter.

    using (StreamWriter writer = new StreamWriter("H:\\myName\\Desktop\\Fed_Sec_Lending.txt"))
    

    i.e.

    string textvalmatd = textReader.Value;
    writer.Write(textvalmatd + ",");
    

    for everything where:

    Trace.Write(textvalmatd + ",");
    

    would have been.

    Thanks for the help for the few people that commented.

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

Sidebar

Related Questions

I have an activity using an xml layout where a WebView is embedded. I
Well, code speaks more (I have hard-coded some things, to isolate the problem and
Maybe this is a very silly question but I'm new using django. I have
very strange. I have a layout resource, which besides others defines a text view:
I have two lists. The first one is hard-coded and the contents never change.
The new helper methods EditorFor, TextBoxFor are very cool in avoiding hard coded field
I have the following xml and want to insert additional xml into it: <root>
I'm having a very hard time trying to access a custom configuration section in
I wanna diplay a Stopwatch timer... using Asp.Net C#... I have looked through many
I'm having a little bit of a dilemma. I have a very basic class

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.