Text Document Object Model classes
Text Document Object Model (TextDOM) represents text document as a tree of objects. This tree matches internal document structure.Text file content gets parsed and validated automatically using Schema Object Model (TextSOM) classes and top-level classes.
Text DOM classes allow you to load documents and document fragments, validate them, create, modify and save back Text DOM objects to a file or text stream.
Technically, DOM is a class hierarchy based on TextNode class which defines all the basic node functionality.
Here is the list of derived classes:
- TextString - represents a fixed string of text (terminal lexeme).
- TextChar - represents a single character corresponding character class in schema.
- TextRule - text data structure, represented by its content.
- TextDocument - represents a top-level text data structure which keeps a link to the whole format schema and provide document-level functionality.
To obtain object content, you need to use Content property.
Also, for debugging purposes, you may get special text representation of object using ToString() overridden method.
Below are properties and methods of these classes. TextNode methods and properties are not listed below for classes derived from TextNode, but, of course, they are inherited.
Class TextNode
public abstract class TextNode : ICloneable, IEnumerable, ITextNavigable
Represents the root class for the DOM hierarchy. Every object in a document is a TextNode.
Property | Type | Description |
ParentNode | TextNode, get/set | The parent TextNode of this TextNode. |
Position | long, get/set | Offset for the node from the beginning of the document. Set by TextReader. |
NextSibling | TextNode, get only | The next sibling of this TextNode. Returns null if this is the last item. |
PreviousSibling | TextNode, get only | The previous sibling of this TextNode. Returns null if this is the first item. |
OwnerDocument | TextDocument, get only | The owner document of this TextNode. Returns null if the root node is not TextDocument. |
RootNode | TextNode, get only | The root node. Returns TextDocument unless this node is in a document fragment. |
SchemaInfo | ITextSchemaInfo, get/set | Node schema information object. Created by TextReader and TextValidator. |
HasChildNodes | bool, get only | Returns true if this node has child nodes. If this node could potentially have child nodes (TextRule), but actually has none, this property will return false. |
ChildNodes | TextNodeList, get only | Returns a list of child nodes. If this node cannot have child nodes, returns null. |
Size | long, get only | Returns size of this node in characters. |
Capacity | long, get only | Returns number of bytes this node could contain. |
Description | string, get only | Returns description for the node. |
Content | string, get/set | Represents content of the node. Is is possible to set contents of the node using this property.
However, keep in mind that TextStrings without SchemaInfo has unlimited Capacity and will absorb the rest of the data. To fill complex structures correctly, you need to use parsing, i.e., ReadFrom method. |
NodeType | TextNodeType, get only | Returns type of the node. |
Method | Parameters | Description |
CreateNavigator | returns TextPathNavigator | Implementation of ITextNavigable.CreateNavigator. Returns a TextPathNavigator for this node. |
WriteTo | TextWriter, returns void | Saves a node contents to a stream. |
ReadFrom | TextReader stream, TextEventHandler handler, returns void | Reads text data to this node. TextChar and textString just fills themselves with data from stream, according to Capacity value.
TextRule and TextDocument do real data parsing with validations and error handling.
Calls back handler on errors. |
Class TextChar
public class TextChar : TextNode
This class represents a single character of specified class.
Constructor | Parameters | Description |
TextChar | None | Default constructor. |
TextChar | char | Creates a value filled by char. |
TextChar | TextChar | Copy constructor. |
Method | Parameters | Description |
SetContent | char, returns long | Set content from a given char. |
Validate | returns bool | Validates character against its SchemaInfo, if present. Returns true if character is valid. |
ToString | returns void | Textual representation of object. |
Class TextString
public class TextString : TextNode
This class represents a terminal string in a document.
If TextString does not have SchemaInfo (pattern to compare), it has unlimited Capacity (-1) and will absorb all data from input stream (in ReadFrom method).
Constructor | Parameters | Description |
TextString | None | Default constructor. Creates an empty string. |
TextString | string | Creates an initialized string. |
TextString | TextString | Copy constructor. |
Method | Parameters | Description |
Validate | returns bool | Validates string against its SchemaInfo, if present. Returns true if string is the same as SchemaInfo pattern. |
ToString | returns void | Textual representation of object. |
Class TextRule
public class TextRule : TextNode
This class organizes a hierarchy structure in a document. It is a container for other TextNodes and has a set of methods and properties manage these nodes.
Initially, TextRule instance is "anonymous", i.e., does not have any specific content pattern. Rule has a type and could be parsed or validated only if SchemaInfo is assigned.
Please do not use TextNodeList methods to add/insert/delete nodes, because they will not correctly assign parent node for child nodes. Use TextRule methods instead.
Constructor | Parameters | Description |
TextRule | None | Default constructor. Creates an empty rule of unknown type. |
TextRule | TextRule | Copy constructor. |
Property | Type | Description |
Item (indexer) | long, get only | Returns TextNode child item by index. |
FirstTerminalPosition | long, get only | Returns position of the first terminal (string, char) child item. It could be different from position of the Rule itself if IgnoreWitheSpace option is used in header. |
FirstChild | TextNode, get only | Returns first child item. |
LastChild | TextNode, get only | Returns last child item. |
Method | Parameters | Description |
AppendChild | TextNode newChild, returns TextNode | Appends an item to the list of nodes. Returns appended node. |
InsertAfter | TextNode newChild, TextNode refChild, returns TextNode | Inserts an item to the list of nodes after refChild. Returns inserted node. |
InsertBefore | TextNode newChild, TextNode refChild, returns TextNode | Inserts an item to the list of nodes before refChild. Returns inserted node. |
PrependChild | TextNode newChild, returns TextNode | Inserts an item to the beginning of the list of nodes. Returns inserted node. |
RemoveChild | TextNode child, returns TextNode | Removes an item from the list of nodes, if specified node was a child of the structure; otherwise does nothing. Returns removed node. |
RemoveFirstChild | returns void | Removes the first item from the list of child nodes. |
RemoveLastChild | returns void | Removes the last item from the list of child nodes. |
RemoveAll | returns void | Removes all items from the list of child nodes. |
ReplaceChild | TextNode newChild, TextNode oldChild, returns TextNode | Replaces oldChild with newChild, if oldChild was a child of the structure; otherwise does nothing. Returns newChild node. |
ConvertToString | returns void | Convert all TextRule content into a single string and insert it as a sole child node. |
ToString | returns void | Textual representation of object. |
Class TextDocument
public class TextDocument : TextRule
This class represents a text document. It is derived from TextRule, therefore, it provides all TextRule functionality.
Also, TextDocument includes a set of static helper methods to create and initialize various TextNode classes, to simplify automated document creation from client software.
Constructor | Parameters | Description |
TextDocument | None | Default constructor. Creates an empty document of unknown type. |
TextDocument | TextDocument | Copy constructor. |
Property | Type | Description |
Schema | TextSchema, get/set | Schema for use to parse/validate this document. |
Method | Parameters | Description |
static CreateRule | TextNode[] nodes, returns TextRule | Helper function which creates unnamed TextRule and fills it with child nodes. |
static CreateChar | char value, returns TextChar | Helper function which creates TextChar and assigns it a value. |
static CreateString | string data, returns TextString | Helper function which creates TextString and fills it with data. |
CreateRule | string name, returns TextRule | Helper function which creates TextRule with appropriate SchemaInfo of a specified type. |
Validate | TextSchema schema, TextEventHandler handle, returns void | Validates document against the schema. Initializes Schema property. |
Class TextNodeList
public class TextNodeList : HugeList<TextNode>
This class represents a list of nodes and provides a full set of functionality for manipulations with this list.
BinNodeList is based on generic HugeList doubly-linked list.
Class TextException
public class TextException : SystemException
This class is a class of exception objects thrown when text document parsed, validated or incorrectly manipulated.
Constructor | Parameters | Description |
TextException | TextNode obj | Constructs an exception with source node. |
TextException | TextNode obj, string message | Constructs an exception with source node and a message. |
TextException | TextNode obj, string message, long pos | Constructs an exception with source node, a message and a position. |
TextException | TextNode obj, string message, Exception e | Constructs an exception with source node, a message and inner exception. |
Property | Type | Description |
Position | long, get only | Returns position of the error in a document. |
SourceNode | TextNode, get only | Returns node which caused the exception. |
Class TextEventArgs
public class TextEventArgs : EventArgs
Contains information about error or warning occured during text document processing.
Constructor | Parameters | Description |
TextEventArgs | TextException e, SeverityType s | Initializes object with appropriate values. |
Property | Type | Description |
Exception | TextException, get only | Returns exception information. |
Severity | SeverityType, get only | Returns information about severity of error. |
Enumeration TextNodeType
public enum TextNodeType
Represents type of node.
Member | Description |
CHAR | The node is a single character. |
STRING | The node is string. |
RULE | The node is a rule. |
DOCUMENT | The node is a document. |
Delegate TextEventHandler
public delegate void TextEventHandler(
Object sender,
TextEventArgs e
);
Represents the callback method that will handle text document parsing/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