OpenPetra
Free Administration Software for Non-Profits
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
Ict.Common.IO.TSimpleYmlParser Class Reference

TSimpleYmlParser is mainly used for restoring a database saved as yml.gz; avoids loading a huge XmlDocument with all tables at once. for smaller files, the other implementation, TYml2Xml, is much easier to step through, since you get an XmlDocument More...

Inheritance diagram for Ict.Common.IO.TSimpleYmlParser:
Ict.Common.IO.TYml2Xml

Public Member Functions

 TSimpleYmlParser (string AFilename)
 constructor More...
 
 TSimpleYmlParser (string[] ALines)
 constructor More...
 
void ParseCaptions ()
 parse all captions, ie nodes that do not have attributes, but children More...
 
bool StartParseList (string ACaption)
 parse a list of simple rows, with their attributes More...
 
SortedList< string, string > GetNextLineAttributes ()
 get the attributes of the next row More...
 
XmlDocument ParseYML2XML ()
 loads an yml document into one xml document More...
 
XmlDocument ParseYML2XML (XmlDocument AMergeDoc, int ADepth)
 merges several yml documents into one xml document, and maintains their inheritance hierarchy for nodes that have the same name More...
 
XmlNode ParseYML2TaskListRoot ()
 loads an yml document into one xml document; then returns only the part meant to be passed directly to a TaskList constructor as the TaskList root. More...
 

Static Public Member Functions

static string GetElementName (XmlNode ANode)
 return either the name from the attribute, or the element name More...
 
static bool CheckName (string AElementName)
 check if the name can be used as an element name for XML More...
 
static string Xml2YmlGz (XmlDocument ADoc)
 format the XML into zipped YML and return as Base64 string More...
 
static string Xml2Yml (XmlDocument ADoc)
 format the XML into YML and return as string More...
 
static bool Xml2Yml (XmlDocument ADoc, string AOutYMLFile)
 format the XML into YML to increase readability and save to file More...
 
static bool ReadHeader (string AFilename, out string baseYamlOrClass)
 This method can be used to check if this is the correct file type, and also find out the baseyaml or baseclass More...
 
static SortedList ReferenceNodes (XmlDocument myDoc)
 fill sorted list which contains a reference to each node by name More...
 
static XmlDocument CreateXmlDocument ()
 create an empty xml document, which will be filled with the data from the yaml file More...
 
static bool Merge (ref XmlDocument AMergeDoc, XmlDocument ANewDoc, int ADepth)
 merge the specificDoc into the mergeDoc. merges 2 xml documents, maintains their inheritance hierarchy for nodes that have the same name. allows caching of base yaml files. More...
 
static List< XmlNode > GetChildren (XmlNode node, bool AConsiderBase)
 get all children nodes of a given node; depending on parameter, include the inherited nodes or not the nodes will be sorted by the order flag (AlwaysFirst, AlwaysLast) More...
 
static XmlNode Parent (XmlNode node)
 get the parent node More...
 
static void SetAttribute (XmlNode xmlNode, string name, string value)
 SetAttribute will never consider the base and the xml hierarchy; use Tag to move things to base. More...
 
static void ClearAttribute (XmlNode xmlNode, string name)
 remove attribute More...
 
static bool HasAttribute (XmlNode xmlNode, string name)
 check for the attribute; if the current node does not have it, check the base node More...
 
static string GetAttribute (XmlNode xmlNode, string name)
 get the attribute; if the current node does not have it, check the base node More...
 
static string GetAttributeRecursive (XmlNode xmlNode, string name)
 if the current node does not have the attribute, try the parent nodes More...
 
static bool HasAttributeRecursive (XmlNode xmlNode, string name)
 if the current node does not have the attribute, try the parent nodes More...
 
static SortedList< string, string > GetAttributes (XmlNode xmlNode)
 get all attributes, even from base node More...
 
static XmlNode GetChild (XmlNode node, string childName)
 get the child node with the given name; considers base nodes as well More...
 
static StringCollection GetElements (XmlNode node, string childName)
 overload for GetElements, with the main node and the name of the child node that has the elements More...
 
static StringCollection GetElements (XmlNode node)
 
static void Tag (XmlNode ANode)
 Tag will move all leafs to a new child element called base a leaf is an XmlNode that has no children, only attributes all attributes are moved to base can only be called once todo: what about sequences More...
 

Static Public Attributes

const string XMLLIST = "XmlList"
 the name used for elements in a list More...
 
const string XMLELEMENT = "XmlElement"
 the name used for elements in generated xml code More...
 
const string ROOTNODEINTERNAL = "RootNodeInternal"
 the name used for root node in generated xml code More...
 

Protected Member Functions

void ThrowException (string AMessage, Int32 lineNr)
 throw an exception and tell the current position while reading the yaml file More...
 
Int32 GetAbsoluteIndentation (Int32 lineNr)
 
Int32 GetAbsoluteIndentationNext (Int32 lineNr)
 
Int32 GetIndentationNext (Int32 lineNr)
 
string GetNextLine ()
 does not return comment lines More...
 
bool SplitNode (string line, out string nodeName, out string nodeContent)
 split a line into the node name and the node content More...
 
string StripQuotes (string s)
 strip the quotes from a string More...
 

Static Protected Member Functions

static XmlNode LoadChild (XmlNode parent, string nodeName, int ADepth)
 
static XmlNode GetBaseNode (XmlNode ANode)
 check if parent already has a base element More...
 

Protected Attributes

string[] lines = null
 contains the lines of the yml document More...
 
Int32 currentLine = -1
 the current line that we are parsing More...
 
string filename = ""
 the filename of the file that we are parsing More...
 

Detailed Description

TSimpleYmlParser is mainly used for restoring a database saved as yml.gz; avoids loading a huge XmlDocument with all tables at once. for smaller files, the other implementation, TYml2Xml, is much easier to step through, since you get an XmlDocument

Constructor & Destructor Documentation

◆ TSimpleYmlParser() [1/2]

Ict.Common.IO.TSimpleYmlParser.TSimpleYmlParser ( string  AFilename)
inline

constructor

Parameters
AFilename

◆ TSimpleYmlParser() [2/2]

Ict.Common.IO.TSimpleYmlParser.TSimpleYmlParser ( string[]  ALines)
inline

constructor

Member Function Documentation

◆ CheckName()

static bool Ict.Common.IO.TYml2Xml.CheckName ( string  AElementName)
inlinestaticinherited

check if the name can be used as an element name for XML

◆ ClearAttribute()

static void Ict.Common.IO.TYml2Xml.ClearAttribute ( XmlNode  xmlNode,
string  name 
)
inlinestaticinherited

remove attribute

Parameters
xmlNode
name

◆ CreateXmlDocument()

static XmlDocument Ict.Common.IO.TYml2Xml.CreateXmlDocument ( )
inlinestaticinherited

create an empty xml document, which will be filled with the data from the yaml file

◆ GetAbsoluteIndentation()

Int32 Ict.Common.IO.TYml2Xml.GetAbsoluteIndentation ( Int32  lineNr)
inlineprotectedinherited

returns -1 for comments or invalid line numbers, otherwise the number of spaces throws exception if there is a tab in the indentation

◆ GetAbsoluteIndentationNext()

Int32 Ict.Common.IO.TYml2Xml.GetAbsoluteIndentationNext ( Int32  lineNr)
inlineprotectedinherited
Returns
the absolute indentation of the next valid line (skipping comments)

◆ GetAttribute()

static string Ict.Common.IO.TYml2Xml.GetAttribute ( XmlNode  xmlNode,
string  name 
)
inlinestaticinherited

get the attribute; if the current node does not have it, check the base node

◆ GetAttributeRecursive()

static string Ict.Common.IO.TYml2Xml.GetAttributeRecursive ( XmlNode  xmlNode,
string  name 
)
inlinestaticinherited

if the current node does not have the attribute, try the parent nodes

◆ GetAttributes()

static SortedList< string, string > Ict.Common.IO.TYml2Xml.GetAttributes ( XmlNode  xmlNode)
inlinestaticinherited

get all attributes, even from base node

Parameters
xmlNode
Returns

◆ GetBaseNode()

static XmlNode Ict.Common.IO.TYml2Xml.GetBaseNode ( XmlNode  ANode)
inlinestaticprotectedinherited

check if parent already has a base element

◆ GetChild()

static XmlNode Ict.Common.IO.TYml2Xml.GetChild ( XmlNode  node,
string  childName 
)
inlinestaticinherited

get the child node with the given name; considers base nodes as well

Parameters
node
childName
Returns

◆ GetChildren()

static List< XmlNode > Ict.Common.IO.TYml2Xml.GetChildren ( XmlNode  node,
bool  AConsiderBase 
)
inlinestaticinherited

get all children nodes of a given node; depending on parameter, include the inherited nodes or not the nodes will be sorted by the order flag (AlwaysFirst, AlwaysLast)

Parameters
node
AConsiderBaseinclude the inherited nodes
Returns

◆ GetElementName()

static string Ict.Common.IO.TYml2Xml.GetElementName ( XmlNode  ANode)
inlinestaticinherited

return either the name from the attribute, or the element name

◆ GetElements() [1/2]

static StringCollection Ict.Common.IO.TYml2Xml.GetElements ( XmlNode  node)
inlinestaticinherited

convert elements of a sequence into a string collection checks for duplicates, and removes names with a tilde character ~ in front

◆ GetElements() [2/2]

static StringCollection Ict.Common.IO.TYml2Xml.GetElements ( XmlNode  node,
string  childName 
)
inlinestaticinherited

overload for GetElements, with the main node and the name of the child node that has the elements

Parameters
node
childName
Returns

◆ GetIndentationNext()

Int32 Ict.Common.IO.TYml2Xml.GetIndentationNext ( Int32  lineNr)
inlineprotectedinherited
Returns
+1 if next line is more indented than the current line (skipping comments), -1 if next line is less indented, or current line is last line 0 if current line has same identation than the next line

◆ GetNextLine()

string Ict.Common.IO.TYml2Xml.GetNextLine ( )
inlineprotectedinherited

does not return comment lines

Returns
null if no line available

◆ GetNextLineAttributes()

SortedList< string, string > Ict.Common.IO.TSimpleYmlParser.GetNextLineAttributes ( )
inline

get the attributes of the next row

Returns

◆ HasAttribute()

static bool Ict.Common.IO.TYml2Xml.HasAttribute ( XmlNode  xmlNode,
string  name 
)
inlinestaticinherited

check for the attribute; if the current node does not have it, check the base node

◆ HasAttributeRecursive()

static bool Ict.Common.IO.TYml2Xml.HasAttributeRecursive ( XmlNode  xmlNode,
string  name 
)
inlinestaticinherited

if the current node does not have the attribute, try the parent nodes

◆ LoadChild()

static XmlNode Ict.Common.IO.TYml2Xml.LoadChild ( XmlNode  parent,
string  nodeName,
int  ADepth 
)
inlinestaticprotectedinherited

TYml2Xml.LoadChild will either reuse an element, move an existing leaf from base to the main node, or create a new element

◆ Merge()

static bool Ict.Common.IO.TYml2Xml.Merge ( ref XmlDocument  AMergeDoc,
XmlDocument  ANewDoc,
int  ADepth 
)
inlinestaticinherited

merge the specificDoc into the mergeDoc. merges 2 xml documents, maintains their inheritance hierarchy for nodes that have the same name. allows caching of base yaml files.

◆ Parent()

static XmlNode Ict.Common.IO.TYml2Xml.Parent ( XmlNode  node)
inlinestaticinherited

get the parent node

◆ ParseCaptions()

void Ict.Common.IO.TSimpleYmlParser.ParseCaptions ( )
inline

parse all captions, ie nodes that do not have attributes, but children

◆ ParseYML2TaskListRoot()

XmlNode Ict.Common.IO.TYml2Xml.ParseYML2TaskListRoot ( )
inlineinherited

loads an yml document into one xml document; then returns only the part meant to be passed directly to a TaskList constructor as the TaskList root.

Returns

◆ ParseYML2XML() [1/2]

XmlDocument Ict.Common.IO.TYml2Xml.ParseYML2XML ( )
inlineinherited

loads an yml document into one xml document

Returns

◆ ParseYML2XML() [2/2]

XmlDocument Ict.Common.IO.TYml2Xml.ParseYML2XML ( XmlDocument  AMergeDoc,
int  ADepth 
)
inlineinherited

merges several yml documents into one xml document, and maintains their inheritance hierarchy for nodes that have the same name

Parameters
AMergeDoc
ADepth
Returns

◆ ReadHeader()

static bool Ict.Common.IO.TYml2Xml.ReadHeader ( string  AFilename,
out string  baseYamlOrClass 
)
inlinestaticinherited

This method can be used to check if this is the correct file type, and also find out the baseyaml or baseclass

Returns
false if the yaml file cannot be read or interpreted

◆ ReferenceNodes()

static SortedList Ict.Common.IO.TYml2Xml.ReferenceNodes ( XmlDocument  myDoc)
inlinestaticinherited

fill sorted list which contains a reference to each node by name

◆ SetAttribute()

static void Ict.Common.IO.TYml2Xml.SetAttribute ( XmlNode  xmlNode,
string  name,
string  value 
)
inlinestaticinherited

SetAttribute will never consider the base and the xml hierarchy; use Tag to move things to base.

◆ SplitNode()

bool Ict.Common.IO.TYml2Xml.SplitNode ( string  line,
out string  nodeName,
out string  nodeContent 
)
inlineprotectedinherited

split a line into the node name and the node content

◆ StartParseList()

bool Ict.Common.IO.TSimpleYmlParser.StartParseList ( string  ACaption)
inline

parse a list of simple rows, with their attributes

Parameters
ACaption
Returns

◆ StripQuotes()

string Ict.Common.IO.TYml2Xml.StripQuotes ( string  s)
inlineprotectedinherited

strip the quotes from a string

◆ Tag()

static void Ict.Common.IO.TYml2Xml.Tag ( XmlNode  ANode)
inlinestaticinherited

Tag will move all leafs to a new child element called base a leaf is an XmlNode that has no children, only attributes all attributes are moved to base can only be called once todo: what about sequences

Parameters
ANode

◆ ThrowException()

void Ict.Common.IO.TYml2Xml.ThrowException ( string  AMessage,
Int32  lineNr 
)
inlineprotectedinherited

throw an exception and tell the current position while reading the yaml file

◆ Xml2Yml() [1/2]

static string Ict.Common.IO.TYml2Xml.Xml2Yml ( XmlDocument  ADoc)
inlinestaticinherited

format the XML into YML and return as string

◆ Xml2Yml() [2/2]

static bool Ict.Common.IO.TYml2Xml.Xml2Yml ( XmlDocument  ADoc,
string  AOutYMLFile 
)
inlinestaticinherited

format the XML into YML to increase readability and save to file

◆ Xml2YmlGz()

static string Ict.Common.IO.TYml2Xml.Xml2YmlGz ( XmlDocument  ADoc)
inlinestaticinherited

format the XML into zipped YML and return as Base64 string

Member Data Documentation

◆ currentLine

Int32 Ict.Common.IO.TYml2Xml.currentLine = -1
protectedinherited

the current line that we are parsing

◆ filename

string Ict.Common.IO.TYml2Xml.filename = ""
protectedinherited

the filename of the file that we are parsing

◆ lines

string [] Ict.Common.IO.TYml2Xml.lines = null
protectedinherited

contains the lines of the yml document

◆ ROOTNODEINTERNAL

const string Ict.Common.IO.TYml2Xml.ROOTNODEINTERNAL = "RootNodeInternal"
staticinherited

the name used for root node in generated xml code

◆ XMLELEMENT

const string Ict.Common.IO.TYml2Xml.XMLELEMENT = "XmlElement"
staticinherited

the name used for elements in generated xml code

◆ XMLLIST

const string Ict.Common.IO.TYml2Xml.XMLLIST = "XmlList"
staticinherited

the name used for elements in a list


The documentation for this class was generated from the following file: