I am trying to parse through a group of XML files in Qt 3.3.7 following the Blanchette and Summerfield guide book on how to parse XML files using SAX. I have created a class called InterceptReader which looks identical to their SaxHandler class except instead of making a QListView I just have a couple QStrings to store information during the parsing and an additional function called getIds( char*, char* ) which creates 2 char*s and uses strdup( ) to allocate and create these char*s so I can use them outside the class. The two char *s are the pieces of data I am concerned about when parsing through the XML file and which is stored in QStrings.

I then in my calling class have a function called openXMLFiles( ) which looks like this (sorry for any misspellings, my code is on a stand-alone machine with no network connectivity):

Qt Code:
  1. QDir xmlDir = QDir( xmlDirString, QString( "*.xml" ) );
  2. InterceptReader intReader;
  3. reader.setContentHandler( &intReader );
  4. read.setErrorHandler( &intReader );
  5. int numFiles = xmlDir.count( );
  6. for( int i = 0 ; i < numFiles ; i++ )
  7. {
  8. QFile file( xmlDir[i] );
  9. reader.parse( &file );
  10. char *ref;
  11. char *diff;
  12. intReader.getEventIds( ref, diff ); // These char*s are malloced using strdup
  13. if( ref && diff )
  14. {
  15. fprintf( stderr, "ref = %s, diff = %s\n", ref, diff );
  16. free( ref );
  17. ref = NULL;
  18. free( diff );
  19. diff = NULL;
  20. }
  21. else if( ref && !diff )
  22. {
  23. fprintf( stderr, "ref = %s\n", ref );
  24. free( ref );
  25. ref = NULL;
  26. }
  27. else if( !ref && diff )
  28. {
  29. fprintf( stderr, "diff = %s\n", diff );
  30. free( diff );
  31. diff = NULL;
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 

I plan to do more with this code later but wanted to make sure I was parsing it correctly. But for ever file I print out an error that says "Line 1, column 1: unexpected end of file". I have opened the XML files and they are filled out as well as being used by other programs. And I am basically using the SAX reader in the Qt 3 book verbatim as of right now. Any ideas why I would be getting this end of file error on a valid XML file? I am relatively new to XML but thought parsing through the file should be simple. Thanks for your help!