Brunet.Applications.ConfigurationValidator.Validate C# (CSharp) Method

Validate() public method

Read xml file and check validity using given xsd file. brunet and ipop configuration file input type is file name, and dhcp configuration file content is passed as a string.
public Validate ( string config_path, string xsd_path ) : bool
config_path string
xsd_path string
return bool
    public bool Validate(string config_path, string xsd_path)
    {
      _failed = false;

      Assembly assem = Assembly.GetExecutingAssembly();
      Stream schema_stream = assem.GetManifestResourceStream(xsd_path);
      XmlSchema test_schema = XmlSchema.Read(schema_stream, null);

      XmlReaderSettings settings = new XmlReaderSettings();
      settings.ValidationType = ValidationType.Schema;
      XmlSchemaSet schemas = new XmlSchemaSet();
      settings.Schemas = schemas;
      schemas.Add(test_schema);
      settings.ValidationEventHandler += ValidEventHandler;
      XmlReader validator = XmlReader.Create(config_path, settings);

      while(validator.Read() && !_failed);
      validator.Close();

      if(_failed) {
        throw new Exception(_message);
      }

      return true;
    }

Usage Example

        public virtual int Parse(string[] args)
        {
            try {
                _options.Parse(args);
            } catch (Exception e) {
                _error_message = e.Message;
                return(-1);
            }

            if (_node_config_path == string.Empty || !System.IO.File.Exists(_node_config_path))
            {
                _error_message = "Missing NodeConfig";
                return(-1);
            }

            try {
                Validator.Validate(_node_config_path, NODE_XSD);
                _node_config      = Utils.ReadConfig <NodeConfig>(_node_config_path);
                _node_config.Path = _node_config_path;
            } catch (Exception e) {
                _error_message = "Invalid NodeConfig file: " + e.Message;
                Console.WriteLine(e);
                return(-1);
            }

            return(0);
        }
All Usage Examples Of Brunet.Applications.ConfigurationValidator::Validate
ConfigurationValidator