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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:53:37+00:00 2026-05-25T11:53:37+00:00

I try to use LINQ to read XML file. However, the string which store

  • 0

I try to use LINQ to read XML file. However, the string which store the value of selected attribute is always empty.

Here is the code:

        string output = "";
        XDocument loaded = XDocument.Load(@"d:\input.xml");

        var ta = from tmp in loaded.Descendants("NewDataSet.Table")
                select tmp.Element("E1");

        foreach (string ss in ta)
        {
            ouput += ss;

        }

The output string is always empty. But the ss string has correct value.

What is the problem?

I’ve no idea how to add xml file with style. So i have to update the xml file as image. 🙁
enter image description 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-05-25T11:53:38+00:00Added an answer on May 25, 2026 at 11:53 am

    Now that you have shown your XML, here’s how to fix your code:

    var ta = from tmp in loaded.Descendants("Table")
             select tmp.Element("E1");
    

    You do not use . in XML as you do in C# to navigate the XML tree. You could also navigate a XML tree using XPath:

    var ta = from tmp in loaded.XPathSelectElements("NewDataSet/Table/E1")
             select tmp;
    

    Also I would recommend you to use a StringBuilder instead of string concatenations for this output variable:

    var ta = from tmp in loaded.Descendants("Table")
             select tmp.Element("E1");
    
    var builder = new StringBuilder();
    foreach (string ss in ta)
    {
        builder.Append(ss);
    }
    string output = builder.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use XDocument (XML Linq) to save and load classes. For this
I try to use the winDBG to debug a dump file. When I run
I try to use the following code: ArrayList<String> Map<String, String> Eclipse complains about both
I use linq-sql and this is what I need. Sub Commit() Try StepStart: Transaction
I would like to read/write encrypted XML files using LINQ to XML. Does anyone
I have created small test web application which makes use of LINQ to SQL.
I have an xml string that I wish to traverse using LINQ to XML
I'm trying to use LINQ to XML to create an Excel spreadsheet. I created
I'm seeing strange behavior when I try to parse XML using the LINQ XmlReader
I aim to try use DevExpress web server controls (which are awesome) in an

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.