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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:11:51+00:00 2026-05-31T19:11:51+00:00

Hey i am unable to figure out why this xml is not being generated

  • 0

Hey i am unable to figure out why this xml is not being generated properly.

Here is my xml being generated:

<?xml version="1.0"?>
   <schedules>

      <schedule>
         <Name>Schedule0</Name>

         <Task 0>
         <description>task0 description</description>
         <done>true</done>
         </Task 0>

         <Task 1>
         <description>task1 description</description>
         <done>true</done>
         </Task 1>   
      </schedule>

     <schedule>
        <Name>Schedule1</Name>
        <Task 0>
        <description>task0 description</description>
        <done>true</done>
        </Task 0>

        <Task 1>
        <description>task1 description</description>
        <done>true</done>
        </Task 1>
    </schedule>

     <schedule>
       <Name>Schedule2</Name>
       <Task 0>
       <description>task0 description</description>
       <done>true</done>
       </Task 0>

       <Task 1>
       <description>task1 description</description>
       <done>true</done>
       </Task 1>
    </schedule>

    <schedule>
     <Name>Schedule3</Name>
     <Task 0>
     <description>task0 description</description>
     <done>true</done>
     </Task 0>

     <Task 1>
     <description>task1 description</description>
     <done>true</done>
     </Task 1>
    </schedule>

    <schedule>
      <Name>Schedule4</Name>
      <Task 0>
      <description>task0 description
      </description>
      <done>true</done>
      </Task 0>

      <Task 1>
      <description>task1 description</description>
      <done>true</done>
      </Task 1>
    </schedu

And my c# code :

        XmlTextWriter xmlwriter = new XmlTextWriter("mojixml",null);

        xmlwriter.WriteStartDocument();
        xmlwriter.WriteStartElement("schedules");

        for (int i = 0; i < 5; i++)
        {
            xmlwriter.WriteStartElement("schedule");
            xmlwriter.WriteElementString("Name", "Schedule"+i.ToString());

            for (int ii = 0; ii < 2; ii++)
            {
                xmlwriter.WriteStartElement("Task " + ii.ToString());
                xmlwriter.WriteElementString("description", "task"+ii+ " description");
                xmlwriter.WriteElementString("done", "true");
                xmlwriter.WriteEndElement();
            }
            xmlwriter.WriteEndElement();    //schedule
        }

        xmlwriter.WriteEndElement();    //schedules

        xmlwriter.WriteEndDocument();

also when i change the outer loop range from 5 to 3 it doesn’t show any xml(empty file).

  • 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-31T19:11:53+00:00Added an answer on May 31, 2026 at 7:11 pm

    You’re never closing or flushing your writer – you’re getting to the end of the program, at which point you’ve got a writer with the XML in its buffer, waiting to be written… but your program just quits. Just putting it in a using statement will do the right thing, disposing of the stream appropriately, even if there’s an exception:

    using (XmlTextWriter xmlwriter = new XmlTextWriter("mojixml", null))
    {
    }
    

    However, it would be better still to use XmlWriter.Create:

    using (XmlWriter xmlwriter = XmlWriter.Create("schedules.xml"))
    {
    }
    

    At this point you’ll also need to fix your generation code not to create an element name with a space in it:

    xmlwriter.WriteStartElement("Task " + ii.ToString());
    // becomes...
    xmlwriter.WriteStartElement("Task" + ii.ToString());
    

    Also note that all those calls to ToString are unnecessary – you can leave the compiler to do that.

    Finally, I’d suggest that unless you’re building a huge file, it would be simpler to use LINQ to XML to build a document in memory and then write it out at the end.

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

Sidebar

Related Questions

Hey I am getting this error: error: conversion to non-scalar type requested Here are
Hey all i am trying to figure out a way to delete something inside
Hey all, my Computational Science course this semester is entirely in Java. I was
hey there guys and girls i have this code that saves json as a
Hey, how this is written in VB.NET? This was an example I found on
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey all. Okay here is the situation. I would like to be able to
Hey bloggers out there! I've created Wordpress blog that I am hosting myself, and
hey guys, I'm totally inexperienced in terms of threads, so here's my question: How
Hey guys! I have this little problem: I have one ViewController which adds 2

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.