Hi,
I'm using Xerces distrib 2.1.0 in a c++ application
on MacOS 9.2. There is my code for parse a xml file :
//
------------------------------------------------------------------
// // ------------------------------------------------------------------ OSErr XercesProcessFileTest(char*
fileIn)
{ char* Message = NULL; Str255 theFile; int32 NbArticles; char* TestContenu = NULL; const char* xmlFile = 0; AbstractDOMParser::ValSchemes valScheme = AbstractDOMParser::Val_Auto; bool doNamespaces = false; bool doSchema = false; bool schemaFullChecking = false; bool doList = false; bool errorOccurred = false; DOMNode
*ArticleNode;
DOMNode *TexteNode; DOMNode *GestionNode; DOMNamedNodeMap *MapArticle; DOMNamedNodeMap *MapGestion; #if MACOS int16 i; STRCPY(theFile,
"\p/");
STRCAT(theFile, (uchar*)fileIn); // Now replace ':' by '/' for(int16 i = 1; i <= theFile[0]; i++) { if(theFile[i] == ':') theFile[i] = '/'; } P2CSTR(theFile); #else STRCPY(theFile, fileIn); #endif try{
GetInfos(); XMLPlatformUtils::Initialize(); } catch(const XMLException &toCatch) { Message = XMLString::transcode(toCatch.getMessage()); MessageBox(NULL, P_CHAR Message, STR_ERROR, MB_ICONINFORMATION | MB_OK); if(Message) delete Message; Message = NULL; } // Creation et configuration du parser. { DOMDocument *doc = 0; static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS); DOMBuilder *parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0); parser->setFeature(XMLUni::fgDOMNamespaces, doNamespaces); parser->setFeature(XMLUni::fgXercesSchema, doSchema); parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking); if (valScheme ==
AbstractDOMParser::Val_Auto)
{ parser->setFeature(XMLUni::fgDOMValidateIfSchema, true); } else if (valScheme == AbstractDOMParser::Val_Never) { parser->setFeature(XMLUni::fgDOMValidation, false); } else if (valScheme == AbstractDOMParser::Val_Always) { parser->setFeature(XMLUni::fgDOMValidation, true); } // enable datatype normalization -
default is off
parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true); // And create our error handler and
install it
MyErrorHandler2 errorHandler; parser->setErrorHandler(&errorHandler); errorHandler.resetErrors(); //Parsage et interception des
erreurs
try{ parser->resetDocumentPool(); doc = parser->parseURI((char*)theFile); } catch (const XMLException& e) { Message = XMLString::transcode(e.getMessage()); MessageBox(NULL, P_CHAR Message, STR_ERROR_PARSE, MB_OK|MB_ICONEXCLAMATION); errorOccurred = true; if(Message) delete Message; Message = NULL; } catch (const DOMException& e) { Str255 StrMessage; STRCPY(StrMessage, P_CHAR (e.code)); MessageBox(NULL, P_CHAR StrMessage, STR_ERROR_PARSE, MB_OK|MB_ICONEXCLAMATION); errorOccurred = true; } catch (...) { MessageBox(NULL, STR_ERROR_PARSE, STR_ERROR_PARSE, MB_OK|MB_ICONEXCLAMATION); errorOccurred = true; } if ((!errorOccurred) &&
(!errorHandler.getSawErrors())) {
if (doc) { NbArticles = (doc->getElementsByTagName((XMLString::transcode((char*)STR_TAG_STORY))))->getLength(); if (NbArticles == 0) { MessageBox(NULL, STR_ERROR_NOSTORY, STR_ERROR, MB_OK|MB_ICONEXCLAMATION); return -1; } // On prend le 1er élément <ARTICLE> ArticleNode =
(doc->getElementsByTagName((XMLString::transcode((char*)STR_TAG_STORY))))->item(0);
// On le mape MapArticle = getMap(ArticleNode); // On prend l'élément
<GESTION>
GestionNode = MapArticle->getNamedItem((XMLString::transcode((char*)STR_TAG_GESTION))); MapGestion = getMap(GestionNode); // Here we call a funtion that write the
text in a window....
} } // Delete the parser
itself. Must be done prior to calling Terminate, below.
parser->release(); } // Deinit Xerces XMLPlatformUtils::Terminate(); return noErr; } //
------------------------------------------------------------------
// Renvoit la map d'une node // ------------------------------------------------------------------ DOMNamedNodeMap* getMap(DOMNode* Node) { DOMNamedNodeMap *map = Node->getAttributes(); DOMNodeList *liste = Node->getChildNodes(); DOMNode *node; int i; int taille = liste->getLength();
for (i=0 ;i<taille;i++){
try { node = liste->item(i)->cloneNode(true); } catch (const DOMException& e) { Str255 StrMessage1; STRCPY(StrMessage1, P_CHAR (e.code)); MessageBox(NULL, P_CHAR StrMessage1, STR_ERROR_PARSE, MB_OK|MB_ICONEXCLAMATION); } try { map->setNamedItem(node); // Here is the error, I go into catch below but e.code has a value
// far too high for a normal DOMException error
code
} catch (const DOMException& e) { Str255 StrMessage2; STRCPY(StrMessage2, P_CHAR (e.code)); MessageBox(NULL, P_CHAR StrMessage2, STR_ERROR_PARSE, MB_OK|MB_ICONEXCLAMATION); } return map; } This function "getmap" was correct with old distrib 1.7.0. What's wrong
today ?
Guillaume
|