void XMLRuntime::read(const string& filename, FreeAX25::Runtime::Configuration& config) { XercesDOMParser parser; parser.setValidationScheme(XercesDOMParser::Val_Always); parser.setDoNamespaces(true); parser.setDoSchema(true); parser.setDoXInclude(true); parser.setHandleMultipleImports(true); parser.setValidationSchemaFullChecking(true); parser.setCreateEntityReferenceNodes(false); parser.setIncludeIgnorableWhitespace(false); DOMTreeErrorReporter errReporter; parser.setErrorHandler(&errReporter); parser.parse(filename.c_str()); if (errReporter.getSawErrors()) throw exception(); // Now read configuration from the DOM Tree: XERCES_CPP_NAMESPACE::DOMDocument* doc = parser.getDocument(); assert(doc != nullptr); auto rootElement = doc->getDocumentElement(); auto configName = rootElement->getAttribute(toX("name")); config.setId(fmX(configName)); { // Get settings: auto nodeList = rootElement->getElementsByTagName(toX("Settings")); if (nodeList->getLength() > 0) readSettings( "", static_cast<DOMElement*>(nodeList->item(0)), config.settings); } { // Get plugins: auto nodeList = rootElement->getElementsByTagName(toX("Plugins")); if (nodeList->getLength() > 0) readPlugins( "", static_cast<DOMElement*>(nodeList->item(0)), config.plugins); } }
/* * Load datas */ int CApp::loadXercesData( dlgAmonSoft &amon ) { try { XERCES_CPP_NAMESPACE::DOMDocument *pDoc = g_Parser->getDocument(); XERCES_CPP_NAMESPACE::DOMElement *pElem = pDoc->getDocumentElement(); CheckDataFileVersion( pElem, amon ); DOMNodeList *pNodeList = pElem->getChildNodes (); uint size = pNodeList->getLength(); for( uint i = 0; i < size; i++ ) { DOMNode *pNode = pNodeList->item( i ); if( XMLString::equals( XMLString::transcode( pNode->getNodeName() ), "Personne" ) ) { QString string; Datas::CPersonnes *pPersonne = new Datas::CPersonnes; DOMElement *elmt = static_cast< DOMElement* >( pNode ); mAssert( elmt != 0, "elmt != 0" ); pPersonne->loadFromXML( elmt ); QListView *listView = amon.getListViewPersonnes(); QListViewItem *item = new QListViewItem( listView, pPersonne->getNom(), pPersonne->getPrenom(), pPersonne->getTelephone(), pPersonne->getEmail(), string.setNum( pPersonne->getID() ) ); Datas::g_listPersonnes.push_back( pPersonne ); } } } catch( DOMException &e ) { qDebug( XMLString::transcode( e.getMessage() ) ); } return 0; }
int main( int aArgC, char *aArgV[] ) { std::cout << "**************** starting" << std::endl; for( int i = 0; i < 100; ++i ) { XERCES_CPP_NAMESPACE::XMLPlatformUtils::Initialize(); //XERCES_CPP_NAMESPACE::DOMDocument * doc = createNewDoc(); XERCES_CPP_NAMESPACE::DOMDocument * doc = createNewDocWithType(); std::cout << " - Doing something with the document" << std::endl; //delete doc; doc->release(); usleep(100000); std::cout << "* Memory (rss): " << getMemorySize() << std::endl; XERCES_CPP_NAMESPACE::XMLPlatformUtils::Terminate(); std::cout << "* Memory (rss): " << getMemorySize() << std::endl; } std::cout << "**************** ending" << std::endl; return 0; }
void XmlPropertyReader::parseGameObjectFile(Ogre::DataStreamPtr &stream, const Ogre::String &groupName) { initializeXml(); XERCES_CPP_NAMESPACE::DOMDocument* doc = loadDocument(stream); DOMNodeList* godefsXml = doc->getDocumentElement()->getElementsByTagName(AutoXMLCh("gameobjectclass").data()); for (unsigned int idx = 0; idx < godefsXml->getLength(); idx++) { PropertyRecordPtr ps(new PropertyRecord()); DOMElement* curNode = static_cast<DOMElement*>(godefsXml->item(idx)); const DOMNamedNodeMap* godefAttrs = curNode->getAttributes(); for (XMLSize_t attrIdx = 0; attrIdx < godefAttrs->getLength(); attrIdx++) { PropertyEntry entry = processProperty(static_cast<DOMAttr*>(godefAttrs->item(attrIdx))); if (entry.first != "") { ps->setProperty(entry.first, entry.second); } } DOMNodeList* godefChildren = curNode->getChildNodes(); for (XMLSize_t childIdx = 0; childIdx < godefChildren->getLength(); childIdx++) { DOMNode* curChild = godefChildren->item(childIdx); if (curChild->getNodeType() == DOMNode::ELEMENT_NODE) { PropertyEntry entry = processProperty(static_cast<DOMElement*>(curChild)); if (entry.first != "") { ps->setProperty(entry.first, entry.second); } } } mPropertyRecords.push_back(ps); } shutdownXml(); }
bool XML_File_Intf::read_process_plan (const ACE_TCHAR *file) { DANCE_TRACE("XML_File_Intf::read_process_plan"); try { if (!XML_Helper_type::XML_HELPER.is_initialized ()) return false; DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("XML_File_Intf::read_process_plan - ") ACE_TEXT ("Constructing DOM\n"))); XERCES_CPP_NAMESPACE::DOMDocument *dom = XML_Helper_type::XML_HELPER.create_dom ((file)); if (dom == 0) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("XML_File_Intf::read_process_plan - ") ACE_TEXT ("Failed to open file %s\n"), file)); return false; } XERCES_CPP_NAMESPACE::DOMElement *foo = dom->getDocumentElement (); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("XML_File_Intf::read_process_plan - ") ACE_TEXT ("DOMElement pointer: %u\n"), foo)); ID_Map::TSS_ID_Map* TSS_ID_Map (ACE_Singleton<ID_Map::TSS_ID_Map, ACE_Null_Mutex>::instance()); (*TSS_ID_Map)->reset (); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("XML_File_Intf::read_process_plan - ") ACE_TEXT ("Parsing XML file with XSC\n"))); deploymentPlan dp = DAnCE::Config_Handlers::reader::DeploymentPlan (dom); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("XML_File_Intf::read_process_plan - ") ACE_TEXT ("Processing using config handlers\n"))); DP_Handler dp_handler (dp); this->idl_dp_.reset (dp_handler.plan ()); if (this->idl_dp_.get ()) return true; } catch (const CORBA::Exception &ex) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("XML_File_Intf::caught - ") ACE_TEXT ("CORBA Exception whilst parsing XML into IDL\n"), ex._info ().c_str ())); throw Config_Error (this->file_, ex._info ().c_str ()); } catch (const Config_Error &ex) { throw ex; } catch (...) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("XML_File_Intf::caught - ") ACE_TEXT ("Unexpected exception whilst parsing XML into IDL.\n"))); throw Config_Error (this->file_, ACE_TEXT ("Unexpected C++ exception whilst parsing XML")); } return false; }
int HttpServer::svc(void) { char buf[2048]; buf[2047] = '\0'; // security ACE_Time_Value timeout; timeout.sec(5); ssize_t size = peer().recv(buf, 2040, &timeout); if (size > 5) { try { int startUrlOffset = 5; // get rid of "GET /" from Http request, so skip 5 chars char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP"); // detect location of post-URL trailing stuff if(!stopUrl) { throw (CStdString("Malformed http request")); ; } *stopUrl = '\0'; // Remove post-URL trailing stuff CStdString url(buf+startUrlOffset); int queryOffset = url.Find("?"); if (queryOffset > 0) { // Strip beginning of URL in case the command is received as an URL "query" of the form: // http://hostname/service/command?type=ping url = url.Right(url.size() - queryOffset - 1); } CStdString className = UrlSerializer::FindClass(url); ObjectRef objRef = ObjectFactory::GetSingleton()->NewInstance(className); if (objRef.get()) { objRef->DeSerializeUrl(url); ObjectRef response = objRef->Process(); if(response.get() == NULL) { throw (CStdString("Command does not return a response:") + className); } else { DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm()); XERCES_CPP_NAMESPACE::DOMDocument* myDoc; myDoc = impl->createDocument( 0, // root element namespace URI. XStr("response").unicodeForm(), // root element name 0); // document type object (DTD). response->SerializeDom(myDoc); CStdString pingResponse = DomSerializer::DomNodeToString(myDoc); CStdString httpOk("HTTP/1.0 200 OK\r\nContent-type: text/xml\r\n\r\n"); peer().send(httpOk, httpOk.GetLength(), MSG_NOSIGNAL); peer().send(pingResponse, pingResponse.GetLength(), MSG_NOSIGNAL); myDoc->release(); } } else { throw (CStdString("Command not found:") + className); ; } } catch (CStdString &e) { CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n"); error = error + e + "\r\n"; peer().send(error, error.GetLength(), MSG_NOSIGNAL); } catch(const XMLException& e) { CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nXML Error\r\n"); peer().send(error, error.GetLength(), MSG_NOSIGNAL); } } else { CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n"); peer().send(notFound, notFound.GetLength(), MSG_NOSIGNAL); } return 0; }