Example program for reading and manipulating the quantitation.xml file.
#include "msparser.hpp"
#include <iostream>
using namespace matrix_science;
int main(int argc, char * argv[])
{
if ( argc < 3 )
{
std::cout << "The location of quantitation.xml file has to be specified as a parameter" << std::endl;
std::cout << "The location should either be the full path to the file" << std::endl;
std::cout << "or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi" << std::endl;
std::cout << "The second parameter should specify schema file path, for instance C:\\quantitation_1.xsd" << std::endl;
std::cout << "It should be either relative to the local quantitation.xml path or to the current folder" << std::endl;
return 1;
}
ms_connection_settings cs;
if (argc > 3)
{
cs.setSessionID(argv[3]);
}
ms_quant_configfile file(argv[1], argv[2], &cs);
if (!file.isValid())
{
std::cout << "There are errors. Cannot continue. The last error description:" << std::endl;
std::cout << file.getLastErrorString() << std::endl;
return 1;
}
int n = file.getNumberOfMethods();
std::cout << "There are " << n << " methods available:" << std::endl;
int i = 0;
for(i=0; i < n; i++)
{
std::cout << file.getMethodByNumber(i)->getName() << std::endl;
}
ms_xml_schema schemaFile;
schemaFile.setFileName(argv[2]);
schemaFile.read_file();
if (!schemaFile.isValid())
{
std::cout << "Errors while reading schema-file. The last error description:" << std::endl;
std::cout << schemaFile.getLastErrorString() << std::endl;
return 1;
}
std::string strValidationErrors = file.validateDocument();
if ( !strValidationErrors.empty() )
{
printf("Initial document validation errors: %s\n", strValidationErrors.c_str());
}
for(i = 0; i < n; i++)
{
const ms_quant_method *pMethod = file.getMethodByNumber(i);
std::string strErrors = pMethod->validateShallow(&schemaFile);
if ( !strErrors.empty() )
{
printf("Method %s\n", pMethod->getName().c_str());
printf("Shallow validation errors: %s\n\n", strErrors.c_str());
}
strErrors = pMethod->validateDeep(&schemaFile);
if ( !strErrors.empty() )
{
printf("Method %s\n", pMethod->getName().c_str());
printf("Deep validation errors: %s\n\n", strErrors.c_str());
}
}
ms_quant_configfile configFileInvalid;
ms_quant_method myMethodInvalid(*file.getMethodByNumber(0));
myMethodInvalid.setName("");
std::string strErr1 = myMethodInvalid.validateShallow(&schemaFile);
printf("shallow validation of a method: %s\n", strErr1.c_str());
std::string strErr2 = myMethodInvalid.validateDeep(&schemaFile);
printf("deep validation of a method: %s\n", strErr2.c_str());
std::string strErr3 = schemaFile.validateComplexObject(&myMethodInvalid, true);
printf("deep validation using schema-object: %s\n", strErr3.c_str());
std::string strErr4 = schemaFile.validateSimpleString(myMethodInvalid.getName().c_str(),
myMethodInvalid.getNameSchemaType().c_str());
printf("attribute validation: %s\n", strErr4.c_str());
configFileInvalid.appendMethod(&myMethodInvalid);
std::string errMethod = configFileInvalid.validateDocument();
printf("document validation errors: %s\n", errMethod.c_str());
if (!configFileInvalid.isValid())
{
std::cout << "Errors in config-file object. The last error description:" << std::endl;
std::cout << configFileInvalid.getLastErrorString() << std::endl;
}
configFileInvalid.setFileName("quantitation_temp.xml");
configFileInvalid.save_file();
if (!configFileInvalid.isValid())
{
std::cout << "Errors in config-file object. The last error description:" << std::endl;
std::cout << configFileInvalid.getLastErrorString() << std::endl;
}
return 0;
}