I'm quite new to TinyXml and I'm having some problems.I'm trying to learn how to create and read files.
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 main page but when I recreate this file it fails to load
Here is my code to recreate that file:
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 ?