Text Schema Object Model classes
The Text Schema Object Model (TextSOM) is API that allows you to create, edit, and validate schemas programmatically.Text Schema is a collection of objects that could be compiled, verified, saved, loaded and used together to parse and validate text documents.
Every class in SOM have its own ToString() method overridden which should be used to re-create schema text from its internal representation. This allows to inspect all optimization performed during schema compilation.
Class TextSchemaObject
public class TextSchemaObject
Represents the root class for the SOM hierarchy.
Property | Type | Description |
Parent | TextSchemaGroup, get/set | The parent group of this TextSchemaObject. |
Type | TextItemType, get | Type of this TextSchemaObject. |
Flagged | bool, get | True if one of Flags (Optional, ZeroPlus, OnePlus) is set. |
Optional | bool, get/set | Get/Set Optional (?) status of this TextSchemaObject. |
OnePlus | bool, get/set | Get/Set OnePlus (+) status of this TextSchemaObject. |
ZeroPlus | bool, get/set | Get/Set ZeroPlus (*) status of this TextSchemaObject. |
Method | Parameters | Description |
SetFlagsFrom | TextSchemaObject, returns void | Set flags from given TextSchemaObject. |
UpdateFlagsFrom | TextSchemaObject, returns void | Update/Merge flags from given TextSchemaObject. For example, '+' and '?' will be '*'. |
Class TextSchemaString
public class TextSchemaString : TextSchemaObject
This class represents a fixed string in a schema.
Constructor | Parameters | Description |
TextSchemaString | None | Default constructor. Initialized as empty string. |
Property | Type | Description |
Name | string, get/set | Content of string. |
CaseSensitive | bool, get/set | Case seisitivity to compare within a document. |
Method | Parameters | Description |
ToString | returns void | Textual representation of object. |
Class TextSchemaChar
public class TextSchemaChar : TextSchemaObject
This class represents a character class in a schema.
Constructor | Parameters | Description |
TextSchemaChar | None | Default constructor. Initializes char with empty specification. |
Property | Type | Description |
Restrictions | string, get/set | Specification of character class, in string form. |
Negative | bool, get/set | Make character class inverted. |
Method | Parameters | Description |
Compile | returns bool | Compile textual specification to internal form. If failed, returns false. |
ToString | returns void | Textual representation of object. |
Class TextSchemaRuleRef
public class TextSchemaRuleRef : TextSchemaObject
This class represents a reference to rule in a schema.
Constructor | Parameters | Description |
TextSchemaRuleRef | None | Default constructor. |
TextSchemaRuleRef | TextSchemaRule | Initializes reference to a given rule. |
Property | Type | Description |
Name | string, get/set | Name of referenced rule. |
TextInclude | bool, get/set | If true, schema parser will replace this rule ref to its content in rule definition. |
Rule | TextSchemaRule, get/set | Referenced rule. |
Method | Parameters | Description |
ToString | returns void | Textual representation of object. |
Class TextSchemaGroup
public class TextSchemaGroup : TextSchemaObject
This class represents a group (sequential or enumeration) in a schema.
Constructor | Parameters | Description |
TextSchemaGroup | None | Default constructor. Creates an empty sequential group. |
TextSchemaGroup | IEnumerable<TextSchemaObject> | Creates a sequential group filled with list members. |
Property | Type | Description |
Items | List<TextSchemaObject>, get | Internal list of itmes. It is not recommended to manipulate text schema objects using this List members directly. Instead, use special methods of TextSchemaGroup. |
Sequential | bool, get/set | If true, group is sequential, if false - enumeration. |
Method | Parameters | Description |
Reparent | returns void | Set parent value of list members to this TextSchemaGroup. May be used to correct parent values if list members were inserted with list methods. |
AddItem | TextSchemaObject, returns void | Append element to the list. |
InsertItem | int idx, TextSchemaObject obj, returns void | Insert element to the list, to position specified by idx. |
AddRange | IEnumerable<TextSchemaObject>, returns void | Append elements to the list. |
InsertRange | int idx, IEnumerable<TextSchemaObject> objs, returns void | Insert elements to the list, to position specified by idx. |
RemoveItem | in idx, returns void | Remove element from the list at position idx. |
ReplaceItem | int idx, TextSchemaObject obj, returns void | Replace element in the list at position idx, to object obj. |
ToString | returns void | Textual representation of object. |
Class TextSchemaRule
public class TextSchemaRule
This class represents a rule in a schema.
Constructor | Parameters | Description |
TextSchemaRule | None | Default constructor. Creates empty rule. |
Property | Type | Description |
RootGroup | TextSchemaGroup, get only | Returns always sequential group of elements representing content of the rule. |
Items | List<TextSchemaObject>, get only | Items of the RootGroup. |
Name | string, get/set | Name of the rule. |
IsDocument | bool, get | True if this rule looks like document root. Set by schema parser. |
IsTerminal | bool, get | True if this rule contains strings and characters only. Set by schema parser. |
IsAllowEmpty | bool, get | True if this rule contains optional elements only. Set by schema parser. |
IsPrivate | bool, get | True if this rule inherited from included file and should not be used as document (root rule). Set by schema parser. |
IsOptimizedGroup | bool, get | True if this rule was optimized (groups reordering) by schema parser. |
IsOptimizedCommonItem | bool, get | True if this rule was optimized (common items optimization) by schema parser. |
IsOptimizedLeftRecursion | bool, get | True if this rule was optimized (left recursion elimination) by schema parser. |
IsOptimizedIndirectLeftRecursion | bool, get | True if this rule was optimized (indirect left recursion elimination) by schema parser. |
Method | Parameters | Description |
ToString | returns void | Textual representation of object. |
Class TextSchema
public class TextSchema
This class represents a text document schema which contains all rules and header options provided in the schema description.
TextSchema validates and compile schema.
Schema must be compiled and must be valid before use for documents parsing and validation.
Constructor | Parameters | Description |
TextSchema | None | Default constructor. |
TextSchema | TextSchema | Copy constructor. |
Property | Type | Description |
MimeTypes | IEnumerable<string>, get only | Returns set of mime types assigned to the current document with "mime_types" header field. |
Extensions | IEnumerable<string>, get only | Returns set of extensions assigned to the current document with "extensions" header field. |
StartRule | TextSchemaRuleRef, get only | Reference to a start document rule. |
StartComments | List<string>, get only | List of allowed start comments literals. |
EndComments | List<string>, get only | List of allowed end comments literals. |
Credits | string, get/set | Represents a credits value from header information block. |
Comments | string, get/set | Represents a comments value from header information block. |
License | string, get/set | Represents a license value from header information block. |
Version | int, get/set | Represents a version value from header information block. |
IgnoreWhiteSpace | bool, get/set | Represents a IgnoreWhiteSpace value from header information block. |
Rules | List<TextSchemaRule>, get only | Provides access to collection of rules. |
Documents | IEnumerable<TextSchemaRule>, get only | Provides access to temporary collection of root rules, excluding ones marked as private. |
IsCompiled | bool, get only | Indicates that the schema is compiled and verified. |
IsValid | bool, get only | Indicates that the schema is valid. |
Method | Parameters | Description |
FindRule | string name, returns TextSchemaRule | Finds a rule by name in internal rules array. If not found, returns null. |
SetMimeTypes | string name, returns void | Sets a string with mime types collection as a comma separated list. |
SetExtensions | string name, returns void | Sets a string with extensions collection as a comma separated list. |
SetStartRule | string name, returns void | Sets a name of start rule. Will be checked on compile stage. |
Compile | TextValidationEventHandler handler, returns void | Compiles a schema and makes optimizations. On error, if handler == null, throws TextSchemaException. |
static Read | ITextSchemaReader reader, TextReader trd, TextValidationEventHandler han, returns BinSchema | Parses a schema loaded from TextReader using ITextSchemaReader interface, compiles a schema and returns it. On error, calls BinValidationEventHandler. |
static Load | Stream dump, returns BinSchema | Deserializes a schema and returns it. |
Save | Stream dump, returns void | Serializes the schema. |
ToString | returns void | Textual representation of object. |
Class TextSchemaException
public class TextSchemaException : SystemException
This class contains exception details for exceptions thrown when TextSchema compiler and validator encounter an error.
Constructor | Parameters | Description |
TextSchemaException | TextSchemaObject obj | Constructs an exception with source object. |
TextSchemaException | TextSchemaObject obj, string message | Constructs an exception with a source object and a message. |
TextSchemaException | TextSchemaObject obj, string message, int line | Constructs an exception with a source object, a message, and a line number. |
TextSchemaException | TextSchemaObject obj, string message, Exception e | Constructs an exception with a source object, a message, and an inner exception. |
Property | Type | Description |
LineNumber | int, get only | Returns a line number of the error (in the bdd file). If the error cannot be linked to a specific line, returns -1. |
SourceSchemaObject | TextSchemaObject, get only | Returns an object which caused the error. |
Class TextSchemaInfo
public class TextSchemaInfo : ITextSchemaInfo
Provides schema information for validated text node.
Constructor | Parameters | Description |
TextSchemaInfo | None | Default constructor. Creates empty schema info object. |
TextSchemaInfo | TextSchemaObject obj, bool isValid | Initializes schema info object with provided values. |
Class TextValidationEventArgs
public class TextValidationEventArgs : EventArgs
Encapsulates information about validation error/warning.
Constructor | Parameters | Description |
TextValidationEventArgs | TextSchemaException, SeverityType severity | Initializes object with provided values. |
Property | Type | Description |
Exception | TextSchemaException, get only | Returns an exception information. |
Severity | SeverityType, get only | Returns an severity of the error. |
Interface ITextSchemaInfo
public interface ITextSchemaInfo
Provides an interface for current node schema information access.
Property | Type | Description |
SchemaObject | TextSchemaObject, get only | Returns a schema object corresponding to the current node. |
Validity | bool, get only | Returns true if schema information is valid (current node is validated successfully). |
Interface ITextSchemaReader
public interface ITextSchemaReader
Defines an interface for schema parsers.
Any class that implements this interface and parses schema description in some format (C-like, XML, etc) and translates it into TextSchema object, could be used as an alternative schema parser.
Method | Parameters | Description |
Parse | TextReader trd, TextSchema schema, TextValidationEventHandler handler, returns void | Reads schema description from TextReader, fills TextSchema and reports errors to handler if it is not null. |
Enumeration TextItemType
public enum TextItemType
Provides information about type of text schema object.
Member | Description |
TI_TYPE_NONE | TextSchemaObject object created by error, not a real text schema type. |
TI_TYPE_STRING | Fixed string |
TI_TYPE_RULE | Rule reference object |
TI_TYPE_GROUP | Group, sequential or enumeration |
TI_TYPE_CHAR | Character class |
Enumeration TextItemFlags
public enum TextItemFlags
Represents flags of item in schema.
Member | Description |
TI_NONE | No flags. |
TI_OPTIONAL | Item is optional (?) |
TI_ZEROPLUS | Item is zero or more (*) |
TI_ONEPLUS | Item is one or more (+) |
Enumeration TextRuleFlags
public enum TextRuleFlags
Represents flags text rule in schema.
Member | Description |
TT_NONE | No flags. |
TT_ROOT | Rule is potential root element |
TT_PRIVATE | Rule is from included file and cannot be root |
TT_TERMINAL | Rule contains characters and strings only and could be represented as a single string |
TT_ALLOWEMPTY | All rule members are optional |
Delegate TextValidationEventHandler
public delegate void textValidationEventHandler(
Object sender,
TextValidationEventArgs e
);
Represents the callback method that will catch text schema validation events.
See also:
- About Miraplacid Binary and Text DOM Library
- Binary Data Definition Language
- BinPath Expression Language
- Text Data Definition Language
- BinaryDOM and TextDOM API
- Binary Schema Object Model (BinSOM) classes
- Binary Document Object Model (BinDOM) classes
- BinPath classes
- Binary Top-Level classes
- Text Schema Object Model (TextSOM) classes
- Text Document Object Model (TextDOM) classes
- Text Navigation classes
- Text Top-Level classes
- BinaryDOM / TextDOM Common classes
- Low-Level classes
- Extension Components
- BinaryDOM PowerShell Snapin
- BinaryDOM SDK examples
- TextDOM SDK examples
- Miraplacid Binary DOM SDK Main Page