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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:33:49+00:00 2026-05-28T00:33:49+00:00

I want to loop through a xml file and display the values in text

  • 0

I want to loop through a xml file and display the values in text box, but my textbox is showing only one value at a time. In debug mode I am able to see all values. Here is my code.

void timer1_Tick(object sender, EventArgs e)
{
    XDocument xd = XDocument.Load(@"D:\satish1\na.xml");
    var query = from p in xd.Descendants("item")
                select new
                {
                    //name = p.Element("title").Value,
                    des = p.Element("description").Value
                };
    foreach (var p in query)
    {
        //tbs.Text = p.name.ToString();
        title.Text = p.des.ToString();
    }
}

How would I repeat all the values continously; my timer’s TimeSpan is 5 seconds.

  • 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-28T00:33:50+00:00Added an answer on May 28, 2026 at 12:33 am

    You are using foreach, hence when ever your code exits the function, you will have only last value assigned to the text box. Do something like this:

    //Have one private variable, to store data from XML
    private int _counter = 0;
    private List<string> _xmlData = new List<string>();
    
    void timer1_Tick(object sender, EventArgs e)
    {
        if(_xmlData.Count == 0) //Populate your list
        {
            _counter = 0;
            XDocument xd = XDocument.Load(@"D:\satish1\na.xml");
            var query = from p in xd.Descendants("item")
                select new
                {
                    des = p.Element("description").Value
                };
            foreach (var p in query) _xmlData.Add(p.des.ToString());
        }
        if(_counter < _xmlData.Count)
             title.Text = _xmlData[_counter];
        _counter++;
        //If you require
        if(_counter == _xmlData.Count)
        {
             timer.Stop(); //Stop the timer
             _xmlData.Clear();
             _counter = 0;
        }
    }
    

    Hope this helps.

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

Sidebar

Related Questions

I have the below but want to only loop through lines in #lines which
Say i want to loop through XML nodes but i want to ignore the
<fx:XML id=dataGridDataFieldsXML source=assets/dataGridDataFieldsXML.xml/> <s:XMLListCollection id=showGridFields source={dataGridDataFieldsXML.viewer}/> I want to loop through my XML file
Introduction: I want to loop through XML files with flexible categories structure. Problem: I
I want to loop over the contents of a text file and do a
I'm new to using XML with C++ and I want to loop through an
In android, through xml parsing i have xml file values in tableview now which
I want to open and read an XML file using php, but I wont
I want to loop through the controls on a UserControl and set a property
I want to loop through a database of documents and calculate a pairwise comparison

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.