Hi I am new to parsing xml and came across tinyxml which seems really good but I am having a lot of problems which are details below and I need to figure it out asap. If anyone can help me I would really appreciate it. Thank you very much.
******************************************************************************
g++ -c -Wall -Wno-unknown-pragmas -Wno-format -O3 Tester2.cpp -o Tester2.o
Tester2.cpp: In function ‘void dump_to_stdout(TiXmlNode*, unsigned int)’:
Tester2.cpp:24:14: error: ‘DOCUMENT’ is not a member of ‘TiXmlNode’
Tester2.cpp:28:14: error: ‘ELEMENT’ is not a member of ‘TiXmlNode’
Tester2.cpp:32:14: error: ‘COMMENT’ is not a member of ‘TiXmlNode’
Tester2.cpp:36:14: error: ‘UNKNOWN’ is not a member of ‘TiXmlNode’
Tester2.cpp:40:14: error: ‘TEXT’ is not a member of ‘TiXmlNode’
Tester2.cpp:45:14: error: ‘DECLARATION’ is not a member of ‘TiXmlNode’
Tester2.cpp: At global scope:
Tester2.cpp:62:1: error: expected unqualified-id before ‘{’ token
make: *** Error 1
******************************************************************************
And from here I do not know how to fix it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi I am new to parsing xml and came across tinyxml which seems really good but I am having a lot of problems which are details below and I need to figure it out asap. If anyone can help me I would really appreciate it. Thank you very much.
The problem is detailed as follows:
/************Problem************/
Basically with the following program:
******************************************************************************
#include "tinyxml.h"
void dump_to_stdout(const char* pFilename){
TiXmlDocument doc(pFilename);
bool loadOkay = doc.LoadFile();
if (loadOkay)
{
printf("\n%s:\n", pFilename);
dump_to_stdout( doc ); // defined later in the tutorial
}
else
{
printf("Failed to load file \"%s\"\n", pFilename);
}
}
int main(void){
dump_to_stdout("example1.xml");
return 0;
}
******************************************************************************
we got the error :
******************************************************************************
g++ -c -Wall -Wno-unknown-pragmas -Wno-format -O3 Tester.cpp -o Tester.o
Tester.cpp: In function ‘void dump_to_stdout(const char*)’:
Tester.cpp:12: error: cannot convert ‘TiXmlDocument’ to ‘const char*’ for argument ‘1’ to ‘void dump_to_stdout(const char*)’
make: *** Error 1
******************************************************************************
Eventually it made sense that the method dump_to_stdout is used twice and they are not the same:
so I tried to use the following:
***********************************************************************
const char * getIndent( unsigned int numIndents ){
static const char * pINDENT = " + ";
static const unsigned int LENGTH = strlen( pINDENT );
if ( numIndents > LENGTH ) numIndents = LENGTH;
return &pINDENT;
}
void dump_to_stdout( TiXmlNode * pParent, unsigned int indent = 0 ){
if ( !pParent ) return;
TiXmlText *pText;
int t = pParent->Type();
printf( "%s", getIndent( indent));
switch ( t )
{
case TiXmlNode::DOCUMENT:
printf( "Document" );
break;
case TiXmlNode::ELEMENT:
printf( "Element \"%s\"", pParent->Value() );
break;
case TiXmlNode::COMMENT:
printf( "Comment: \"%s\"", pParent->Value());
break;
case TiXmlNode::UNKNOWN:
printf( "Unknown" );
break;
case TiXmlNode::TEXT:
pText = pParent->ToText();
printf( "Text: ", pText->Value() );
break;
case TiXmlNode::DECLARATION:
printf( "Declaration" );
break;
default:
break;
}
printf( "\n" );
TiXmlNode * pChild;
for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
{
dump_to_stdout( pChild, indent+2 );
}
}
void load_and_display( )
{
TiXmlBase::SetCondenseWhiteSpace( false );
TiXmlDocument doc( "example1.xml" );
bool loadOkay = doc.LoadFile();
if ( loadOkay )
{
dump_to_stdout( &doc );
}
else
{
printf( "Something went wrong\n" );
}
}
int main(){
load_and_display();
return 0;
}
******************************************************************************
And got the following error:
******************************************************************************
g++ -c -Wall -Wno-unknown-pragmas -Wno-format -O3 Tester2.cpp -o Tester2.o
Tester2.cpp: In function ‘void dump_to_stdout(TiXmlNode*, unsigned int)’:
Tester2.cpp:24:14: error: ‘DOCUMENT’ is not a member of ‘TiXmlNode’
Tester2.cpp:28:14: error: ‘ELEMENT’ is not a member of ‘TiXmlNode’
Tester2.cpp:32:14: error: ‘COMMENT’ is not a member of ‘TiXmlNode’
Tester2.cpp:36:14: error: ‘UNKNOWN’ is not a member of ‘TiXmlNode’
Tester2.cpp:40:14: error: ‘TEXT’ is not a member of ‘TiXmlNode’
Tester2.cpp:45:14: error: ‘DECLARATION’ is not a member of ‘TiXmlNode’
Tester2.cpp: At global scope:
Tester2.cpp:62:1: error: expected unqualified-id before ‘{’ token
make: *** Error 1
******************************************************************************
And from here I do not know how to fix it.
As described by https://www.google.com/accounts, one has to replace "DOCUMENT " by "TINYXML_DOCUMENT" etc.
hth