Exemplo n.º 1
0
int InstallationParser::parse() {
  if (initialization() == 1) // Problem during the initialisation.
    return(1);

  SAXParser* parser = new SAXParser();
  parser->setDoValidation(true);
  parser->setDoNamespaces(true);

  InstallationSAXHandler* handler = new InstallationSAXHandler();
  parser->setDocumentHandler(handler);
  parser->setErrorHandler(handler);
  try {
    const char* file = xmlFile.c_str(); // Name of the descriptor file in the current directory.
    parser->parse(file); // Parsing procedure.
    handler->get_pkgname(pkgname); // Result of the parsing.
	handler->get_pkgUUID(pkgUUID);
	handler->get_implementations(codefiles); // Result of the parsing.
  }
  catch (const XMLException& toCatch) { // File not found for the parsing.
    std::cerr << "\nFile not found : '" << xmlFile << "'\n";
    std::cerr << "Exception message is : \n" << toCatch.getMessage() << "\n";
    return(4);
  }
  int err = handler->get_error(); // The error codes are got from the handler object.
  delete(handler); // Object deleted.
  delete(parser); // Object deleted.
  return(err); // 0, 2 or 3 is returned.
}
Exemplo n.º 2
0
bool streamXML(const string& filename, XMLStream& stream)
{
  try {
    XMLPlatformUtils::Initialize();
  }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    cerr << "XML initialization failed: " << message << endl;
    return false;
  }
  SAXParser parser;
  parser.setDoValidation(true);    // optional.
  parser.setDoNamespaces(true);    // optional
  StreamHandler docHandler(stream);
  parser.setDocumentHandler(&docHandler);
  parser.setErrorHandler((ErrorHandler*)&docHandler);
  try {
    parser.parse(filename.c_str());
  }
  catch (const XMLException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    cerr << "XML Exception: "	<< message << endl;
    return false;
  }
  catch (const SAXParseException& toCatch) {
    char* message = XMLString::transcode(toCatch.getMessage());
    cerr << "XML Parsing exception: "	<< message << endl;
    return false;
  }
  catch (const SAXException& e) {
    char* message = XMLString::transcode(e.getMessage());
    cerr << "Bad file format exception: " << message << endl;
    return false;
  }
  catch (...) {
    cerr << "Unexpected Exception \n" ;
    return false;
  }
  return true;
}