Loading A Schema

The NPCL API provides two classes for loading a schema into memory. To load a schema from an NPCL XML File, use the class NetworkedPlanet.Npcl.XmlSchemaReader. To load a schema from a TMCore topic map, use the class NetworkedPlanet.Npcl.TopicMapSchemaReader. Both of these classes conform to the common interface ISchemaReader.

The ISchemaReader interface defines a boolean property, Strict. If this property is set to true, then the first error encountered in reading schema information will result in an NpclException (or one of its derived classes) being thrown. If this property is set to false, the reader will attempt to recover from any errors it encounters. If Strict is set to false, then after processing, the Errors property of the ISchema interface lists all of the NpclExceptions that were caught and recovered from during processing.

Example 12.4. Reading A Schema

ISchemaReader schemaReader = new XmlSchemaReader( new FileStream("simple-ontology.npcl", FileMode.Open) );
// or with an ITopicMap object called myTopicMap:
// ISchemaReader schemaReader = new XmlSchemaReader( myTopicMap );
schemaReader.Strict = false;
ISchema schema = schemaReader.ReadSchema();
foreach(NpclException error in schema.Errors) {
  System.Console.WriteLine(error.Message);
}