Example program for reading and manipulating the quantitation.xml file.
using System;
using matrix_science.msparser;
namespace MsParserExamples
{
public class config_quantitation
{
public static void Main(string[] argv)
{
if (argv.Length < 2)
{
Console.WriteLine("You must specify quantitation.xml location as the first parameter and the schema path as the second.");
return;
}
ms_quant_configfile file = new ms_quant_configfile(argv[0], argv[1]);
if (!file.isValid())
{
Console.WriteLine("Error number: {0}", file.getLastError());
Console.WriteLine("Error string: {0}", file.getLastErrorString());
return;
}
Console.WriteLine("There are {0} methods available", file.getNumberOfMethods());
for (int i = 0; i < file.getNumberOfMethods(); i++)
{
Console.WriteLine(file.getMethodByNumber(i).getName());
}
ms_xml_schema schemaFile = new ms_xml_schema();
schemaFile.setFileName(argv[1]);
schemaFile.read_file();
if (!schemaFile.isValid())
{
Console.WriteLine("Error while reading schema-file. The last error description:");
Console.WriteLine("Error string: {0}", schemaFile.getLastErrorString());
return;
}
string strValidationErrors = file.validateDocument();
if (strValidationErrors != null && strValidationErrors.Length > 0)
{
Console.WriteLine("Initial document validation errors: {0}", strValidationErrors);
}
for (int i = 0; i < file.getNumberOfMethods(); i++)
{
ms_quant_method pMethod = file.getMethodByNumber(i);
String strErrors = pMethod.validateShallow(schemaFile);
if (strErrors != null && strErrors.Length > 0)
{
Console.WriteLine("Method {0}", pMethod.getName());
Console.WriteLine("Shallow validation errors: {0}", strErrors);
Console.WriteLine();
}
strErrors = pMethod.validateDeep(schemaFile);
if (strErrors != null && strErrors.Length > 0)
{
Console.WriteLine("Method {0}", pMethod.getName());
Console.WriteLine("Deep validation errors: {0}", strErrors);
Console.WriteLine();
}
}
ms_quant_configfile configFileInvalid = new ms_quant_configfile();
ms_quant_method myMethodInvalid = new ms_quant_method(file.getMethodByNumber(0));
myMethodInvalid.setName("");
string strErr1 = myMethodInvalid.validateShallow(schemaFile);
Console.WriteLine("Shallow validation of a method: {0}", strErr1);
string strErr2 = myMethodInvalid.validateDeep(schemaFile);
Console.WriteLine("Deep validation of a method: {0}", strErr2);
string strErr3 = schemaFile.validateComplexObject(myMethodInvalid, true);
Console.WriteLine("Deep validation using schema-object: {0}", strErr3);
string strErr4 = schemaFile.validateSimpleString(myMethodInvalid.getName(),
myMethodInvalid.getNameSchemaType());
Console.WriteLine("Attribute validation: {0}", strErr4);
configFileInvalid.appendMethod(myMethodInvalid);
string errMethod = configFileInvalid.validateDocument();
Console.WriteLine("Document validation errors: {0}", errMethod);
if (!configFileInvalid.isValid())
{
Console.WriteLine("Errors in config-file object. The last error description:");
Console.WriteLine(configFileInvalid.getLastErrorString());
}
configFileInvalid.setFileName("quantitation_temp.xml");
configFileInvalid.save_file();
if (!configFileInvalid.isValid())
{
Console.WriteLine("Errors in config-file object. The last error description:");
Console.WriteLine(configFileInvalid.getLastErrorString());
}
}
}
}