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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:57:15+00:00 2026-05-18T08:57:15+00:00

I want to create XML document with multiple elements inside. The format should be

  • 0

I want to create XML document with multiple elements inside. The format should be something like this:

<Item>
  <Id>2276138</Id> 
  <Title>92907-03100-00 WASHER, CHAIN</Title> 
  <Link>http://www.mywebsite.com/Product.aspx?ProductId=2453575&SKU=92907-03100-00</Link> 
  <Price>0.0000</Price> 
  <Description>WASHER, CHAIN (92907-03100-00)</Description> 
  <Condition>New</Condition> 
  <Brand /> 
  <Product_Type /> 
  <Availability>In Stock</Availability> 
  <Manufacturer>Suzuki</Manufacturer> 
  </Item>

Everything is ok after the first loop of fetching data, but once the 2nd loop is done, I have this:

 <Item></Item>
    <Item>
      <Id>2276138</Id> 
      <Title>92907-03100-00 WASHER, CHAIN</Title> 
      <Link>http://www.mywebsite.com/Product.aspx?ProductId=2453575&SKU=92907-03100-00</Link> 
      <Price>0.0000</Price> 
      <Description>WASHER, CHAIN (92907-03100-00)</Description> 
      <Condition>New</Condition> 
      <Brand /> 
      <Product_Type /> 
      <Availability>In Stock</Availability> 
      <Manufacturer>Suzuki</Manufacturer> 
      </Item>

So after every round of fetching I get the empty item element and just the last element is populated.
Here is the code for the loop:

 while (rdr.Read())
                {
                    if (rdr.HasRows)
                    {
                        XmlElement part = docOrders.CreateElement("Item");
                        id.InnerText = rdr[0].ToString();
                        part.AppendChild(id);
                        title.InnerText = rdr[1].ToString();
                        part.AppendChild(title);
                        link.InnerText = rdr[2].ToString();
                        part.AppendChild(link);
                        price.InnerText = rdr[3].ToString();
                        part.AppendChild(price);
                        desc.InnerText = rdr[4].ToString();
                        part.AppendChild(desc);
                        cond.InnerText = rdr[5].ToString();
                        part.AppendChild(cond);
                        brand.InnerText = rdr[6].ToString();
                        part.AppendChild(brand);
                        productType.InnerText = rdr[7].ToString();
                        part.AppendChild(productType);
                        availability.InnerText = rdr[8].ToString();
                        part.AppendChild(availability);
                        manufacturer.InnerText = rdr[9].ToString();
                        part.AppendChild(manufacturer);                        
                        root.AppendChild(part);
                    }
                }
                rdr.Close();
            }

How Can I solve this, so the data will be fetched correctly?
Thanks in advance

  • 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-18T08:57:16+00:00Added an answer on May 18, 2026 at 8:57 am

    where do you create the id, title, etc. nodes? It looks like you’re reusing these instead of creating new nodes, that’s why it’s not working correctly.

    If you’re reusing a child node, it will remove it from the current node and insert it into the new node, that’s why you’re seeing the empty element.

    Also check this question here on SO, basically the same exact problem.

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

Sidebar

Related Questions

I want to pass xml document to sql server stored procedure such as this:
I want to create a XML editor (form view type) for iphone. Can anyone
I have an XML document and made an XSLT to output is as HTML
I have some XML data that I want to transmit to a web server
I want to be able to write XML to a String with the declaration
I want a TreeView with checkboxes and I'm trying to follow this tutorial .
I have a stored proc that does inserts of people. I have an xml
I have a grails project that contains a few domain objects. I am using
Is there a simple way to read from the global application.exe.config file from a
After scouring the net for answers, coming up with almost solutions... I decided to

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.