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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:20:44+00:00 2026-06-05T20:20:44+00:00

I just started using rapidxml. I 1st create an xml file to read from.

  • 0

I just started using rapidxml. I 1st create an xml file to read from. Worked so fast an easy.

This is what I manual crated.

<?xml version="1.0" encoding="utf-8"?>
<GPS>
    <Path>    
        <Point X="-3684.136" Y="3566.282" Z="285.2893" />
        <Point X="-3681.816" Y="3540.431" Z="283.3658" />
        <Point X="-3687.079" Y="3515.315" Z="282.6284" />
    </Path>
</GPS>

I could easy read that with no problems. I then wanted to write it to a new file.
But the problem is that it keeps overwriting previous xml_nodes.

For example,

<?xml version="1.0" encoding="UTF-8"?>
<GPS>
    <Path>
        <Point X="-3687.08" Y="3515.31" Z="282.628"/>
        <Point X="-3687.08" Y="3515.31" Z="282.628"/>
        <Point X="-3687.08" Y="3515.31" Z="282.628"/>
    </Path>
</GPS>

This is the code that creates that xml file,

int Write(pathStruct *toStore)
{
    xml_document<> doc;

    xml_node<>* decl = doc.allocate_node(node_declaration);
    decl->append_attribute(doc.allocate_attribute("version", "1.0"));
    decl->append_attribute(doc.allocate_attribute("encoding", "UTF-8"));
    doc.append_node(decl);  

    xml_node<> *GPS = doc.allocate_node(node_element, "GPS");
    doc.append_node(GPS);

    cout << "Saving GrindPath " << endl;
    xml_node<> *Path = doc.allocate_node(node_element, "Path");
    GPS->append_node(Path);

    for(int i = 0;i<3;i++) //Temp Static
    {
        xml_node<> *Point = doc.allocate_node(node_element, "Point");
        Path->append_node(Point);

        char x[10];
        FloatToCharA(toStore->X[i], x);
        Point->append_attribute(doc.allocate_attribute("X", x));

        char y[10];
        FloatToCharA(toStore->Y[i], y);
        Point->append_attribute(doc.allocate_attribute("Y", y));

        char z[10];
        FloatToCharA(toStore->Z[i], z);
        Point->append_attribute(doc.allocate_attribute("Z", z));

        //GrindPath->append_node(Point);
        //doc.first_node()->append_node(GrindPath);
        //Point = GrindPath->next_sibling();

        cout << "x:" << toStore->X[i] << "    y:" << toStore->Y[i] << "   z:" << toStore->Z[i] << endl;
    }

    cout << "Done! " << endl;
    std::ofstream myfile;
    myfile.open ("./toStore.xml");
    myfile << doc;
    return 0;

};

My question his how to I stop it from overwriting previous xml_nodes?
I have attempted many thing but every time its still overwrites previous xml_nodes.
I know it must be simple or I am missing the big picture.

Thank you for your help and time!

  • 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-05T20:20:45+00:00Added an answer on June 5, 2026 at 8:20 pm

    I am not sure if this will help but this exists in the documentation:

    One quirk is that nodes and attributes do not own the text of their
    names and values. This is because normally they only store pointers to
    the source text. So, when assigning a new name or value to the node,
    care must be taken to ensure proper lifetime of the string. The
    easiest way to achieve it is to allocate the string from the
    xml_document memory pool. In the above example this is not necessary,
    because we are only assigning character constants. But the code below
    uses memory_pool::allocate_string() function to allocate node name
    (which will have the same lifetime as the document), and assigns it to
    a new node.

    I can see in your code that it appears that your char arrays x, y, z are created in scope of your loop and as such do not satisfy the requirements above.

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

Sidebar

Related Questions

I just started using resharper and it barks at this generated assemblyinfo.cs file. Reason/Logic
I just started using a javascript engine from Microsoft(of IE9?) for developing both desktop
I just started using the CakePHP framework, 2.0 to be precise. I read most
I just started using Selenium 2 tonight so this will be very basic (I
I just started using java so sorry if this question's answer is obvious. I
I just started using Maven and I read that plugins are additional components that
Just started using this technique and am having strange results on the PC side.
I just started using rapidXML since it was recommended to me. Right now to
I just started using/learning Python and have some questions. I have a text file
I just started using git with github. I followed their instructions and ran into

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.