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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:54:37+00:00 2026-06-04T09:54:37+00:00

I want to read below XML format only some attributes are required not All.

  • 0

I want to read below XML format only some attributes are required not All.
For E.g.:

<Parts>
-   <Part>
        <Section>3003512</Section> 
        <Mark>RP-103</Mark> 
        <Length>4950</Length> 
        - <Components>
                <Section>3003512</Section> 
                <Mark>RP-103</Mark> 
                <Length>4950</Length>
                <Remark>System Generated </Remark>
              <Components />
            <Remark>No Comments </Remark>
        </Part>

-   <Part>
        <Section>3003512</Section> 
        <Mark>RP-103</Mark> 
        <Length>4950</Length> 
        <Components />
        <Remark>No Comments </Remark>
     </Part>
</Parts>

I want to Read Only Sections and Mark in Tabular Format. I am using below code to read this But it is giving Error Table Schema ‘Component’ Already Exists .

        DataTable dt = new DataTable();
        DataColumn dc = new DataColumn("Mark");
        DataColumn dc1 = new DataColumn("Sections ");
        dt.Columns.Add(dc); 
        dt.Columns.Add(dc1);
        DataSet dSet = new DataSet();


        if (File.Exists(xmlpath2))
        {

            XmlTextReader Reader1 = new XmlTextReader(xmlpath2);



            dSet.ReadXml(Reader1, XmlReadMode.Auto);


            for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
            {
                DataRow rows = dSet.Tables[0].Rows[i];
                DataRow myRow = dt.NewRow();
                myRow["Mark"] = rows["Mark"];
                myRow["Sections "] = rows["Sections "];

                dt.Rows.Add(myRow);
            }


            GridView1.DataSource = dt;
            GridView1.DataBind(); 

        }
  • 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-04T09:54:39+00:00Added an answer on June 4, 2026 at 9:54 am

    Here’s an example using LINQ to XML:

    var ele = XElement.Parse(xml); // change to XElement.Load if loading from file
    
    var result = ele.Descendants("Section")
                    .Zip(ele.Descendants("Mark"), 
                        (s,m) => new {Section = s.Value, Mark = m.Value});
    

    Now you can create your DataTable:

    var table = new DataTable();
    var marks = new DataColumn("Mark");
    var sections = new DataColumn("Sections");
    
    table.Columns.Add(marks);
    table.Columns.Add(sections);
    
    foreach (var item in result)
    {
        var row = table.NewRow();
        row["Mark"] = item.Mark;
        row["Sections"] = item.Section;
        table.Rows.Add(row);
    }
    

    This will produce:

    Mark     Sections 
    RP-103   3003512 
    RP-103   3003512 
    RP-103   3003512 
    

    It assumes that each Section is followed by a single and corresponding Mark. It also requires System.Xml.Linq and System.Linq.

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

Sidebar

Related Questions

I want to read all XML contents from a file. The code below only
I want to read an existing PDF file, get not only the text, but
I only want to parse an interested element of xml (e.g. see below: class
I want to read the custom XML section from the app.config of a C#
I am trying to read the below xml using XMLDocument, but I am not
I am reading xml gps data using xmlreader.read(). I want to output all coordinate
I have a bash script as below, and I want it to read two
I have a java code to read XML nodes, I want to add in
I want to read a client side XML file uploaded via upload file dialog.
need help to read xml file. i have one xml file which i want

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.