void SAXReader::parse_Object(XMLObj * flegsens_xml_obj) throw(std::runtime_error) { char buf[16384]; int len; //Create the SAX parser and register the C-Style handlers which will call back on this object instace parser = XML_ParserCreate(NULL); XML_SetUserData(parser, (void*)this); XML_SetElementHandler(parser, saxreader_start, saxreader_end); while( !flegsens_xml_obj->eof() && !stop_flag_ ) { flegsens_xml_obj->read( buf, sizeof(buf) ); len = flegsens_xml_obj->gcount(); if (XML_Parse(parser, buf, len, flegsens_xml_obj->eof()) == XML_STATUS_ERROR) { ERROR(logger(), XML_ErrorString(XML_GetErrorCode(parser)) << "at line " << XML_GetCurrentLineNumber(parser)); reset(); throw std::runtime_error("Error in parsing XML input"); } } //Done -> Close the file and free all associated memory parsing_done(); reset(); XML_ParserFree(parser); }
// ---------------------------------------------------------------------- void SAXInterruptibleReader:: parse() throw(runtime_error) { char buf[16384]; int len; stop_flag_ = false; if(!initialized_) open_file(); while(!cache_.empty() && !stop_flag_) { struct CacheData* cd = cache_.front(); switch(cd->tag_type) { case SIR_OPENTAG: start_element(cd->name, cd->atts); break; case SIR_TEXTTAG: text_element(cd->name); break; case SIR_CLOSETAG: end_element(cd->name); break; } cache_.pop_front(); delete cd; } //Read the file until the end of file while( !is_->eof() && !stop_flag_ ) { is_->read( buf, sizeof(buf) ); len = is_->gcount(); if (XML_Parse(parser, buf, len, is_->eof()) == XML_STATUS_ERROR) { std::cerr << XML_ErrorString(XML_GetErrorCode(parser)) << "at line " << XML_GetCurrentLineNumber(parser) << std::endl; reset(); throw std::runtime_error("Error in parsing XML input"); } } //Done -> Close the file and free all associated memory if( !stop_flag_ ) { parsing_done(); reset(); } }
// ---------------------------------------------------------------------- void SAXReader:: parse() throw(std::runtime_error) { char buf[16384]; int len; //Open the file open_file(); //Create the SAX parser and register the C-Style handlers which will call back on this object instace parser = XML_ParserCreate(NULL); XML_SetUserData(parser, (void*)this); XML_SetElementHandler(parser, saxreader_start, saxreader_end); XML_SetCharacterDataHandler(parser, saxreader_text); //Read the file until the end of file while( !is_->eof() && !stop_flag_ ) { is_->read( buf, sizeof(buf) ); len = is_->gcount(); if (XML_Parse(parser, buf, len, is_->eof()) == XML_STATUS_ERROR) { std::cerr << XML_ErrorString(XML_GetErrorCode(parser)) << "at line " << XML_GetCurrentLineNumber(parser) << std::endl; reset(); throw std::runtime_error("Error in parsing XML input"); } } //Done -> Close the file and free all associated memory parsing_done(); reset(); XML_ParserFree(parser); }