Results 1 to 4 of 4

Thread: Anyone know's TinyXML++ and can help ?

  1. #1

    Default Anyone know's TinyXML++ and can help ?

    Hello everyone I'm quite new to Tiny xml and I'm having some problems. What it is I'm trying to learn how to create and read files with tinyxml I can read data from this example

    <?xml version="1.0" standalone=no>
    <!-- Our to do list data -->
    <ToDo>
    <Item priority="1"> Go to the <bold>Toy store!</bold></Item>
    <Item priority="2"> Do bills</Item>
    </ToDo>

    provided on tinyXml main page but when I recreate this file it fails to load

    here is my code to recreate that file


    Updated!! with more readable code

    Code:
     TiXmlDocument document;
    	TiXmlElement * root = 0;
    	TiXmlDeclaration* declar = 0;
    	TiXmlComment * comment = 0;
    
    	// Create declaration
    	declar = new TiXmlDeclaration( "1.0", "", "no" );
    	// Link it to doc
    	document.LinkEndChild( declar );
    
    	// Create Comment
    	comment = new TiXmlComment();
    	comment->SetValue( "Our to do list data" );
    	// Link it to doc
    	document.LinkEndChild( comment );
    
    	// Create root and Link it
    	root = new TiXmlElement( "ToDo" );
    	document.LinkEndChild( root );
    
    	// Create item 1 element
    	TiXmlElement* item1 = new TiXmlElement( "item" );
    
    	// Set Its attribute priority 1
    	item1->SetAttribute( "priority", "1" );
    	// Link text element
    	TiXmlText* item1Text = new TiXmlText( "Go To The" );
    	item1->LinkEndChild( item1Text );
    
    	// Create item1 Bold element
    	TiXmlElement* item1Bold = new TiXmlElement( "Bold" );
    	// Link Text element to bold element
    	TiXmlText* boldText = new TiXmlText( "Toy Store" );
    	item1Bold->LinkEndChild( boldText );
    
    	// Link bold Element to Item element
    	item1->LinkEndChild( item1Bold );
    
    	// Link item element to root node
    	root->LinkEndChild( item1 );
    
    
    	// Create item 2 element
    	TiXmlElement* item2 = new TiXmlElement( "item" );
    
    	// Set its attribute priority 2
    	item2->SetAttribute( "priority", "2" );
    	// And Link Text Item
    	TiXmlText* item2Text = new TiXmlText( "Do Bills" );
    	item2->LinkEndChild( item2Text );
    
    	// Link another item element
    	root->LinkEndChild( item2 );
    
    	// Save
    	document.SaveFile("TestFile.xml");

    Can you tell me please what I'm missing or doing wrong Thank's
    Last edited by rafalmlody12321; 02-24-2015 at 04:49 AM.
    This course is a pain in the as??????? No one said it gonna be a peace of cake


  2. #2
    Join Date
    Nov 2009
    Location
    West Yorkshire
    Posts
    292

    Default

    I've not used it personally (I did the crazy thing and wrote my own XML parser, which for once went fairly well for me). I'm a little confused with what you're saying, it sounds like you've got it reading a file, what do you mean by "recreate that file"? Is it an issue with saving back to file?

    Hard to say without a debugger, I know personally I always get the file directories wrong (forget a sub-folder, or assume the starting point for assets is different to where it actually is), also you save a file called 'TestFile.xml', is that the same name as the XML that's loaded, as it'll overwrite the original one.

  3. #3

    Default

    What I mean by" recreating " is creating xml file from scratch by code. I have that demo.xml file from main web site I've learned how to read data of it and iterate through nodes, so I thought ok now let's learn how to make one, and I started from recreating this demo file, the code works fine it saves file into my project directory "there where the demo file is, but it fails to load, demo file loads fine but my file won't.

    thats the demo file from main page:

    Code:
    <?xml version="1.0" standalone=no>
    <!-- Our to do list data -->
    <ToDo>
    <Item priority="1"> Go to the <bold>Toy store!</bold></Item>
    <Item priority="2"> Do bills</Item>
    </ToDo>

    and this is file created by me

    Code:
    <?xml version="1.0" standalone="no" ?>
    <!--Our to do list data-->
    <ToDo>
        <item priority="1">Go To The
            <Bold>Toy Store</Bold>
        </item>
        <item priority="2">Do Bills</item>
    </ToDo>
    it differs from demo file in format and white spaces maybe that's the problem ?

    I tried to change SetCondenseWhiteSpace() settings but it doesn't change anything, loading file with different encoding doesn't work to. What a great software That can create and save files but it won't load them back Or I'm that thick
    This course is a pain in the as??????? No one said it gonna be a peace of cake


  4. #4

    Default

    Got It !!!!! yeah !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Code:
     TiXmlDocument document;
    	TiXmlElement * root = 0;
    	TiXmlDeclaration* declar = 0;
    	TiXmlComment * comment = 0;
    
    	// Create declaration
    	declar = new TiXmlDeclaration( "1.0", "", "no" );
    	// Link it to doc
    	document.LinkEndChild( declar );
    
    	// Create Comment
    	comment = new TiXmlComment();
    	comment->SetValue( "Our to do list data" );
    	// Link it to doc
    	document.LinkEndChild( comment );
    
    	// Create root and Link it
    	root = new TiXmlElement( "ToDo" );
    	document.LinkEndChild( root ); // here is the problem I've linked root node to document before linking other 
    //elements to root node  when moved that part of
     //  code at the end before I save the file it works  Yeah 
    
    	// Create item 1 element
    	TiXmlElement* item1 = new TiXmlElement( "item" );
    
    	// Set Its attribute priority 1
    	item1->SetAttribute( "priority", "1" );
    	// Link text element
    	TiXmlText* item1Text = new TiXmlText( "Go To The" );
    	item1->LinkEndChild( item1Text );
    
    	// Create item1 Bold element
    	TiXmlElement* item1Bold = new TiXmlElement( "Bold" );
    	// Link Text element to bold element
    	TiXmlText* boldText = new TiXmlText( "Toy Store" );
    	item1Bold->LinkEndChild( boldText );
    
    	// Link bold Element to Item element
    	item1->LinkEndChild( item1Bold );
    
    	// Link item element to root node
    	root->LinkEndChild( item1 );
    
    
    	// Create item 2 element
    	TiXmlElement* item2 = new TiXmlElement( "item" );
    
    	// Set its attribute priority 2
    	item2->SetAttribute( "priority", "2" );
    	// And Link Text Item
    	TiXmlText* item2Text = new TiXmlText( "Do Bills" );
    	item2->LinkEndChild( item2Text );
    
    	// Link another item element
    	root->LinkEndChild( item2 );
    
    	// Save
    	document.SaveFile("TestFile.xml");
    Last edited by rafalmlody12321; 02-24-2015 at 06:31 PM.
    This course is a pain in the as??????? No one said it gonna be a peace of cake


Posting Permissions

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