Simple XML tag validator
Hi
The program is suppose to search tags from xml file and determine does
every tag have a pair, meaning if there is a <start> there must be
</start>, and make count how many there is that particular type. Or in
case <foo/> just take notice and count.
Ok, I have managed to make the program return the tags like below, and
return the value how many tags there is:
things
basket
fruit
/fruit
bug/
/basket
foo/
/things
Now my problem is that I really don't now how to compare is there a
match, and if found how to make sure the found pair is no longer compared.
Now I have put the tags into a two-dimensional array. But I'm wondering
should I use stack or what, and how? My head is empty at the moment, so
any help would be appreciate.
bool getTag( ifstream &in, char tag[], int taglen ) ;
void cleanTag( char tag[], int taglen, int &count ) ;
void printTags( char tags[][30], int count ) ;
int main()
{
int count = 0 ;
char tag[150] ;
char tags[50][30];
ifstream in ;
in.open( "Test1.xml" ) ;
if( !in.is_open() )
cout << "Can't open the file!\n" ;
else
{
while( getTag( in, tag, 150 ) )
{
cleanTag( tag, 30, count ) ;
if( strlen( tag ) != 0 )
strcpy( tags[count-1], tag ) ;
}
}
printTags( tags, count ) ;
return 0 ;
}
void printTags( char tags[][30], int count )
{
for( int i=0; i<count; i++ )
{
for( int j=0; tags[i][j] != '\0'; j++ )
{
cout << tags[i][j] ;
}
cout << endl ;
}
}