| 168 | } |
| 169 | |
| 170 | void XMLFile::parseBuffer_(const std::string & buffer, XMLHandler * handler) |
| 171 | { |
| 172 | // ensure handler->reset() is called to save memory (in case the XMLFile |
| 173 | // reader, e.g. FeatureXMLFile, is used again) |
| 174 | XMLCleaner_ clean(handler); |
| 175 | |
| 176 | StringManager sm; |
| 177 | |
| 178 | // initialize parser |
| 179 | try |
| 180 | { |
| 181 | xercesc::XMLPlatformUtils::Initialize(); |
| 182 | } |
| 183 | catch (const xercesc::XMLException & toCatch) |
| 184 | { |
| 185 | throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, |
| 186 | "", String("Error during initialization: ") + StringManager().convert(toCatch.getMessage())); |
| 187 | } |
| 188 | |
| 189 | // TODO: handle non-plain text |
| 190 | // peak ahead into the file: is it bzip2 or gzip compressed? |
| 191 | // String bz = buffer.substr(0, 2); |
| 192 | |
| 193 | unique_ptr<xercesc::InputSource> source; |
| 194 | { |
| 195 | auto fake_id = sm.convert("inMemory"); |
| 196 | source.reset(new xercesc::MemBufInputSource(reinterpret_cast<const unsigned char *>(buffer.c_str()), buffer.size(), fake_id.c_str())); |
| 197 | } |
| 198 | // what if no encoding given http://xerces.apache.org/xerces-c/apiDocs-3/classInputSource.html |
| 199 | if (!enforced_encoding_.empty()) |
| 200 | { |
| 201 | static const XMLCh* s_enc = xercesc::XMLString::transcode(enforced_encoding_.c_str()); |
| 202 | source->setEncoding(s_enc); |
| 203 | } |
| 204 | |
| 205 | parse(source.get(), handler); |
| 206 | } |
| 207 | |
| 208 | void XMLFile::save_(const String & filename, XMLHandler * handler) const |
| 209 | { |