Results 1 to 2 of 2

Thread: [RESOLVED] rapidxml - overwriting previous xml_nodes

Threaded View

  1. #2

    Thread Starter
    Hyperactive Member Darkened Linux's Avatar
    Join Date
    Jun 2009
    Location
    Canada
    Posts
    296

    Re: rapidxml - overwriting previous xml_nodes

    A little update,

    Someone told me that it holds the address of the var..

    I am not sure if this will help but this exists in the documentation at http://rapidxml.sourceforge.net/manu...inute_tutorial

    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
    So I changed my code up like so..

    Code:
        
    struct charStruct {
    	char X[10];
    	char Y[10];
    	char Z[10];
    };
    
    struct pathStruct {
        	float X[1000];
        	float Y[1000];
        	float Z[1000];
        
    	charStruct X2[1000];
    	charStruct Y2[1000];
    	charStruct Z2[1000];
        }
    Code:
    	for(int i = 0;i<3;i++)
    	{
    		xml_node<> *Point = doc.allocate_node(node_element, "Point");
    		GrindPath->append_node(Point);
    
    		FloatToCharA(toStore->X[i], toStore->X2[i].X);
    		Point->append_attribute(doc.allocate_attribute("X", toStore->X2[i].X));
        ....
        }

    And that fixed everything
    Last edited by Darkened Linux; Jun 16th, 2012 at 12:17 AM.
    [COLOR="Black"]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width