OpenPetra
Free Administration Software for Non-Profits
|
TYml2Xml is able to parse a YML file and store it in an XmlDocument More...
Public Member Functions | |
TYml2Xml (string AFilename) | |
constructor More... | |
TYml2Xml (string[] ALines) | |
constructor More... | |
XmlDocument | ParseYML2XML () |
loads an yml document into one xml document 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... | |
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... | |
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... | |
TYml2Xml is able to parse a YML file and store it in an XmlDocument
Simple YAML to XML converter could have also used http://yaml-net-parser.sourceforge.net/default.html#intro But I prefer to write YAML files but to work with XML in the program. The yaml net parser would just be another interface to understand how to step through the document.
See also the spec http://yaml.org/spec/1.2/
We only support: indentation: http://yaml.org/spec/1.2/#id2577368 only use spaces, no tabs for indentation Each node must be indented further than its parent node. All sibling nodes must use the exact same indentation level.
comment lines start with #, can be indented separators are comma and colon, lists are defined by curly and square brackets {} and [] values can be quoted to escape the colon or comma
name and colon (name:) is converted into an XML element as a parent for the following indented lines indention only happens after node and colon without content scalar: name and colon and a literal is converted into an attribute of the current XML element sequence: [element1, element2, element3] are translated to <element name="element1"/><element name="element2"/> below the parent node mapping: name and value assignments {size=10, help=Test with spaces} are converted into attributes of the parent node
not supported: node names cannot be quoted to escape colons {params: size=10, help=Test with spaces}: leave out the params [=name, =id, address] sorting columns are not identified this way
This class supports the loading of several derived files, and overwriting the data of the base files; todo: make a tag so that everything is pushed into base, before the last file is loaded change the code: move only attributes into base tag add an attribute to elements that have been in base, base="yes" this way the order of elements can be maintained easily, but it is still known which elements and attributes have been added since the tag reactivate the check again, in ProcessXAML.cs: if (TXMLParser.GetAttribute(rootNode, "ClassType") != "abstract") todo: save the last file after modification have been done to the xml structure (eg. loaded from csharp file)
|
inline |
constructor
AFilename |
|
inline |
constructor
|
inlinestatic |
check if the name can be used as an element name for XML
|
inlinestatic |
remove attribute
xmlNode | |
name |
|
inlinestatic |
create an empty xml document, which will be filled with the data from the yaml file
|
inlineprotected |
returns -1 for comments or invalid line numbers, otherwise the number of spaces throws exception if there is a tab in the indentation
|
inlineprotected |
|
inlinestatic |
get the attribute; if the current node does not have it, check the base node
|
inlinestatic |
if the current node does not have the attribute, try the parent nodes
|
inlinestatic |
get all attributes, even from base node
xmlNode |
|
inlinestaticprotected |
check if parent already has a base element
|
inlinestatic |
get the child node with the given name; considers base nodes as well
node | |
childName |
|
inlinestatic |
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)
node | |
AConsiderBase | include the inherited nodes |
|
inlinestatic |
return either the name from the attribute, or the element name
|
inlinestatic |
convert elements of a sequence into a string collection checks for duplicates, and removes names with a tilde character ~ in front
|
inlinestatic |
overload for GetElements, with the main node and the name of the child node that has the elements
node | |
childName |
|
inlineprotected |
|
inlineprotected |
does not return comment lines
|
inlinestatic |
check for the attribute; if the current node does not have it, check the base node
|
inlinestatic |
if the current node does not have the attribute, try the parent nodes
|
inlinestaticprotected |
TYml2Xml.LoadChild will either reuse an element, move an existing leaf from base to the main node, or create a new element
|
inlinestatic |
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.
|
inlinestatic |
get the parent node
|
inline |
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.
|
inline |
loads an yml document into one xml document
|
inline |
merges several yml documents into one xml document, and maintains their inheritance hierarchy for nodes that have the same name
AMergeDoc | |
ADepth |
|
inlinestatic |
This method can be used to check if this is the correct file type, and also find out the baseyaml or baseclass
|
inlinestatic |
fill sorted list which contains a reference to each node by name
|
inlinestatic |
SetAttribute will never consider the base and the xml hierarchy; use Tag to move things to base.
|
inlineprotected |
split a line into the node name and the node content
|
inlineprotected |
strip the quotes from a string
|
inlinestatic |
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
ANode |
|
inlineprotected |
throw an exception and tell the current position while reading the yaml file
|
inlinestatic |
format the XML into YML and return as string
|
inlinestatic |
format the XML into YML to increase readability and save to file
|
inlinestatic |
format the XML into zipped YML and return as Base64 string
|
protected |
the current line that we are parsing
|
protected |
the filename of the file that we are parsing
|
protected |
contains the lines of the yml document
|
static |
the name used for root node in generated xml code
|
static |
the name used for elements in generated xml code
|
static |
the name used for elements in a list