Hi to all,
i'm using the Xerces-C++ DOM-Parser to parse a lot of small XML files in a
directory
and importing the content (with minor changes) into one big DOM. It worked
fine until
i tried to parse also files in subdirectories. The following code fragment
recursively
descends into subdirectories and calls the parser for each appropriate file.
But the parser only accepts files in the original root directory. Files in
subdirectories
cause an exception. It's no OutOfMemoryException, XMLException or
DOMException.
Are there other exceptions that can be handled specific? Why is it raised?
As you can see,
i call the parser with the full pathname.
Thanks for your help.
Martin Kappe
bool CStatCreatorDlg::parseDirectories(DOMDocument *toParseInto, char
*filesToParse, bool bDescend)
{
bool errorsOccured = false;
TCHAR fullPath[_MAX_PATH];
LPTSTR* lpFilePart = NULL;
WIN32_FIND_DATA fileInfo;
HANDLE hFind = ::FindFirstFile(_T("*.*"), &fileInfo);
TCHAR ext [_MAX_EXT];
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // found a
directory
{
CString name = fileInfo.cFileName;
if (name != _T(".") && name != _T("..") && bDescend)
{
// descend into subdirectory
::SetCurrentDirectory(name);
if (!errorsOccured)
errorsOccured = parseDirectories(toParseInto, filesToParse,
bDescend);
::SetCurrentDirectory(_T(".."));
}
}
else // found a file
{
if (GetFullPathName(fileInfo.cFileName, _MAX_PATH, fullPath,
lpFilePart)
!= 0)
{
_tsplitpath(fullPath, NULL, NULL, NULL, ext); // only
want to parse
files
if (strcmp(ext, filesToParse) == 0 && !errorsOccured) // with
right
extension
errorsOccured = parseFile(toParseInto, fullPath);
}
}
} while (::FindNextFile (hFind, &fileInfo));
::FindClose(hFind);
} //if (hFind...)
return errorsOccured;
}
bool CStatCreatorDlg::parseFile(DOMDocument* toParseInto, char *fileToParse)
{
XercesDOMParser *parser = new XercesDOMParser;
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
parser->setCreateEntityReferenceNodes(true);
parser->setExternalNoNamespaceSchemaLocation(m_strTestlogSchema);
DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
parser->setErrorHandler(errReporter);
try
{
parser->parse(XMLString::transcode(fileToParse));
}
catch
--
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner