1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
// In this function the error occures
xmlElement xmlIO::getElements( char *szLine ) {
xmlElement currElem;
currElem.name.assign( (const char*)substr( (const char*)szLine, strsearch( (const char*)szLine, "<" ) + 1, strsearch( (const char*)szLine, ">" ) - 1 ) ); // here the error occures as I try to read in the second element
currElem.attributes = getAttributes( szLine, &currElem ); // <<< under Construction
return currElem;
}
// The class constructor used to read in the XML-File
xmlIO::xmlIO( char *xmlFileIn ) {
// Init Variables and open the file
count = 0;
FILE *xmlDocument;
// Init the arrays
elements = new xmlElement;
attributes = new xmlAttribute;
// Variables when succeeded
char *szBuffer = new char, *szBuff = new char;
int nSearchResult1 = 0, nSearchResult2 = 0;
// Pass the <?xml version="1.0"?> line and read the document element
fscanf( xmlDocument, "%[^\n]s", szBuffer );
if( strsearch( (const char*)szBuffer, "<?" ) != -1 ) {
fgets( szBuffer, strlen( (const char*)szBuffer ), xmlDocument );
fscanf( xmlDocument, "%[^\n]s", szBuffer ); // Read the next line
}
// Search for "<" and ">"
nSearchResult1 = strsearch( (const char*)szBuffer, "<" );
nSearchResult2 = strsearch( (const char*)szBuffer, ">" );
// Don't know why I actually wrote the following... ^^'
// A bit useless security routine as the following "elements" may still be in a non-xml-format...
if( nSearchResult1 == -1 || nSearchResult2 == -1 ) {
err.id = 101;
err.name = "Invalid XML-Format";
err.message = "Die angegebene Datei ist nicht in einem gültigen XML-Format!";
return;
} else {
// Get the document's root xmlElement
document.name = substr( (const char*)szBuffer, nSearchResult1, nSearchResult2 );
// Get all sub elements
while( !feof( xmlDocument ) ) {
fgets( szBuffer, strlen( (const char*)szBuffer ), xmlDocument );
fscanf( xmlDocument, "%[^\n]s", szBuffer );
elements[ count++ ] = getElements( szBuffer );
}
}
// Delete Pointers and close docs
fclose( xmlDocument );
if( logging ) fclose( log );
delete xmlDocument;
delete log;
delete[] szBuffer;
delete[] szBuff;
return;
}
| |