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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:07:00+00:00 2026-05-18T03:07:00+00:00

I am using tinyxml to save data input by the user in a c++

  • 0

I am using tinyxml to save data input by the user in a c++ console program. I pass a save function an array of structs that look like the following

struct day
{
      string name;
      string note;
};

I have seven of these, and pass all seven to the save function that looks like the following

void saveData(day dayArr[])
{
    TiXmlDeclaration* declaration = new TiXmlDeclaration("1.0", "UTF-8", "no");//Create DTD
    TiXmlDocument* doc = new TiXmlDocument;
    doc->LinkEndChild(declaration);

    TiXmlElement* week = new TiXmlElement("week");
    TiXmlElement* day = new TiXmlElement("day");
    TiXmlElement* name = new TiXmlElement("name");
    TiXmlElement* note = new TiXmlElement("note");
    TiXmlElement* tl = new TiXmlElement("tl");
    TiXmlElement* ti = new TiXmlElement("ti");
    TiXmlText* dayName = new TiXmlText("");
    TiXmlText* dayNote = new TiXmlText("");

    for(int i=0; i<7; i++)
    {
        dayName = new TiXmlText(dayArr[i].name.c_str());
        dayNote = new TiXmlText(dayArr[i].note.c_str());
        name->LinkEndChild(dayName);
        note->LinkEndChild(dayNote);
        day->LinkEndChild(name);
        day->LinkEndChild(note);
    }

    week->LinkEndChild(day);
    doc->LinkEndChild(week);

    doc->SaveFile("test.xml");
    cout << "SAVED";
}

It writes this to the file

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<week>
    <day>
        <name>SundayMondayTuesdayWednesdayThursdayFridaySaturday
        </name>
        <note>
        </note>
    </day>
</week>

What i need is this

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<week>
    <day>
        <name>Sunday</name>
        <note>        </note>
    </day>
 <day>
        <name>Monday</name>
        <note>
        </note>
    </day>
 <day>
        <name>Tuesday</name>
        <note>        </note>
    </day>
 <day>
        <name>Wednesday</name>
        <note>        </note>
    </day>
 <day>
        <name>Thursday</name>
        <note>        </note>
    </day>
 <day>
        <name>Friday</name>
        <note>        </note>
    </day>
 <day>
        <name>Saturday</name>
        <note>        </note>
    </day>
</week>

I can’t figure out how to create new elements of the day tag. Thanks in advance for any help.

  • 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-18T03:07:00+00:00Added an answer on May 18, 2026 at 3:07 am

    I haven’t used TinyXml before but looking at the structure of the code, you need to create the day element inside your for loop and add it to the week element 7 times – once for each day.

    Your current code only adds the day element to the week element once at the end – this is reflected in your xml output.

    Taking part of your code – maybe something similar to this below. (This may not compile or be exactly correct but should provide the right idea).

    TiXmlElement* week = new TiXmlElement("week");   
    TiXmlElement* name = new TiXmlElement("name");
    TiXmlElement* note = new TiXmlElement("note");
    TiXmlElement* tl = new TiXmlElement("tl");
    TiXmlElement* ti = new TiXmlElement("ti");
    TiXmlText* dayName = new TiXmlText("");
    TiXmlText* dayNote = new TiXmlText("");
    
    for(int i=0; i<7; i++)
    {
        TiXmlElement* day = new TiXmlElement("day");
        dayName = new TiXmlText(dayArr[i].name.c_str());
        dayNote = new TiXmlText(dayArr[i].note.c_str());
        name->LinkEndChild(dayName);
        note->LinkEndChild(dayNote);
        day->LinkEndChild(name);
        day->LinkEndChild(note);
        week->LinkEndChild(day);
    }
    
    doc->LinkEndChild(week);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
I'm using tinyxml to parse xml files, and I've found that error handling here
I'm using TinyXML to parse/build XML files. Now, according to the documentation this library
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
I'm using TinyXml library for my application but TiXmlDocument object just only can load
I'm using C++, but I think that my question goes beyond a single programming
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.

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.