void SYSTEM::CXMLConfiguration::Parse(std::string xmlcontent) { // ÅäÖýâÎö¹æÔò static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; impl = DOMImplementationRegistry::getDOMImplementation(gLS); if(!impl) return; // throw CException(GET_TEXT(ERR_XML_DOM_IMPLEMENTATION)); if(parser == NULL) parser = new XercesDOMParser; XercesDOMParser* xmlparser = (XercesDOMParser*)parser; xmlparser->setValidationScheme(XercesDOMParser::Val_Never); xmlparser->setLoadExternalDTD(false); xmlparser->setDoNamespaces(false); xmlparser->setDoSchema(false); xmlparser->setValidationSchemaFullChecking(false); xmlparser->setCreateEntityReferenceNodes(false); xmlparser->setIncludeIgnorableWhitespace(false); xmlparser->resetDocumentPool(); //ÖØÖÃÎĵµ»º³å³Ø MemBufInputSource input((XMLByte*) xmlcontent.c_str(), xmlcontent.size(), "memory"); xmlparser->parse(input); doc = xmlparser->getDocument(); if(doc) itemElement = ((XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*)doc)->getDocumentElement(); //¸³Óè¸ù½Úµã else return; // throw CException(boost::str(boost::format(GET_TEXT(ERR_PARSE_CONFIG_FILE)) % xmlcontent)); }
bool SYSTEM::CXMLConfiguration::Open(std::string xmlpath) { // ÅäÖýâÎö¹æÔò static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull }; impl = DOMImplementationRegistry::getDOMImplementation(gLS); if(!impl) return false; // throw CException(GET_TEXT(ERR_XML_DOM_IMPLEMENTATION)); if(parser == NULL) parser = new XercesDOMParser; XercesDOMParser* xmlparser = (XercesDOMParser*)parser; xmlparser->setValidationScheme(XercesDOMParser::Val_Never); xmlparser->setDoNamespaces(false); xmlparser->setDoSchema(false); xmlparser->setValidationSchemaFullChecking(false); xmlparser->setCreateEntityReferenceNodes(false); xmlparser->setIncludeIgnorableWhitespace(false); xmlparser->resetDocumentPool(); //ÖØÖÃÎĵµ»º³å³Ø xmlparser->parse(xmlpath.c_str()); doc = xmlparser->getDocument(); if(doc) itemElement = ((XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument*)doc)->getDocumentElement(); //¸³Óè¸ù½Úµã else return false; //throw CException(boost::str(boost::format(GET_TEXT(ERR_PARSE_CONFIG_FILE)) % xmlpath)); xmlFile = xmlpath; return true; }
//------------------------------------------------------------------------ // // parse - This is the method that is invoked by the rest of // the test program to actually parse an XML file. // //------------------------------------------------------------------------ int ThreadParser::parse(int fileNum) { MemBufInputSource *mbis = 0; InFileInfo *fInfo = &gRunInfo.files[fileNum]; bool errors = false; fCheckSum = 0; if (gRunInfo.inMemory) { mbis = new MemBufInputSource((const XMLByte *) fInfo->fileContent, fInfo->fileSize, fInfo->uFileName, false); } try { if (gRunInfo.dom) { // Do a DOM parse fXercesDOMParser->resetDocumentPool(); if (gRunInfo.inMemory) fXercesDOMParser->parse(*mbis); else fXercesDOMParser->parse(fInfo->fileName); fDoc = fXercesDOMParser->getDocument(); domCheckSum(fDoc); } else if (gRunInfo.sax) { // Do a SAX1 parse if (gRunInfo.inMemory) fSAXParser->parse(*mbis); else fSAXParser->parse(fInfo->fileName); } else { // Do a SAX2 parse if (gRunInfo.inMemory) fSAX2Parser->parse(*mbis); else fSAX2Parser->parse(fInfo->fileName); } } catch (const OutOfMemoryException&) { fprintf(stderr, " during parsing: %s\n OutOfMemoryException.\n", fInfo->fileName); errors = true; } catch (const XMLException& e) { char *exceptionMessage = XMLString::transcode(e.getMessage()); fprintf(stderr, " during parsing: %s\n Exception message is: %s\n", fInfo->fileName, exceptionMessage); XMLString::release(&exceptionMessage); errors = true; } catch (const DOMException& toCatch) { fprintf(stderr, " during parsing: %s\n DOMException code is: %i\n", fInfo->fileName, toCatch.code); errors = true; } catch (const SAXParseException& e) { char *exceptionMessage = XMLString::transcode(e.getMessage()); fprintf(stderr, " during parsing: %s\n Exception message is: %s\n", fInfo->fileName, exceptionMessage); XMLString::release(&exceptionMessage); errors = true; } catch (...) { fprintf(stderr, "Unexpected exception during parsing\n"); errors = true; } delete mbis; if (errors) { fflush(stderr); return 0; // if errors occurred, return zero as if checksum = 0; } return fCheckSum; }