OpenPetra
Free Administration Software for Non-Profits
Ict.Common.IO.TXMLParser Class Reference

This class provides methods for parsing an XML document and assign the contents to a representation in memory. More...

Inheritance diagram for Ict.Common.IO.TXMLParser:
Ict.Tools.DBXML.TDataDefinitionParser

Public Member Functions

 TXMLParser (string filename, Boolean withValidation)
 constructor More...
 
 TXMLParser (string filename)
 constructor; opens the file with validation More...
 
 TXMLParser (XmlDocument ADoc)
 can be used for document that is parsed from YML More...
 
 TXMLParser (TXMLParser AReuseParser)
 copy constructor More...
 
XmlDocument GetDocument ()
 retrieves the document, in case the document should be parsed not by a derived class More...
 

Static Public Member Functions

static string XmlToString (XmlDocument ADoc)
 print an xml document to string; this can be necessary for transmitting between server and client, since XmlDocument is not serializable More...
 
static string XmlToStringIndented (XmlDocument ADoc)
 print an xml document to string with indentation More...
 
static string XmlToString2 (XmlDocument ADoc)
 this is necessary to be able to store XML files that can be parsed by DTD/Schema mechanisms; for YML, we have the name of an element not as an attribute, but the element name itself; this would never work for validating xml; therefore all Elements are called XmlElement, with attribute name More...
 
static XmlNode NextNotBlank (XmlNode cur2)
 test the given node, if it is a comment or is empty; if it is empty, try the next nodes. More...
 
static XmlNode GetNextEntity (XmlNode cur)
 get the next code that is a proper entity (i.e. no comment, not empty) More...
 
static XmlNode GetChild (XmlNode cur, string name)
 return the child with the given name, if it exists; otherwise return null More...
 
static XmlNode FindNodeRecursive (XmlNode AParentNode, string ANodeNameToSearch)
 find a node somewhere in the xml document by its tag name More...
 
static XmlNode FindNodeRecursive (XmlNode AParentNode, string ANodeNameToSearch, string ANameAttribute)
 find a node somewhere in the xml document by its tag name and attribute name More...
 
static void SetAttribute (XmlNode cur, string AAttribName, string AAttribValue)
 add or set an attribute value More...
 
static void RenameAttribute (XmlNode cur, string AAttribOldName, string AAttribNewName)
 rename an existing attribute More...
 
static string GetAttribute (XmlNode cur, string attrib)
 Retrieve an XML attribute. Empty if attribute is not present More...
 
static string GetAttributeRecursive (XmlNode cur, string attrib, bool AInheritAttributes)
 Retrieve an XML attribute. Empty if attribute is not present. Check the parent nodes, if the current node does not have that attribute More...
 
static Boolean HasAttribute (XmlNode cur, string attrib)
 retrieve whether the node has an attribute with the given name or not More...
 
static Int32 GetIntAttribute (XmlNode cur, string attrib)
 retrieve the int value of an attribute. Does prevent unnecessary exceptions, if the attribute is not existing More...
 
static bool GetBoolAttribute (XmlNode cur, string attrib, bool defaultvalue)
 retrieve the boolean value of an attribute. Understands all sorts of notation (yes|no, true|false, 0|1) More...
 
static bool GetBoolAttribute (XmlNode cur, string attrib)
 overload for GetBoolAttribute, assuming default value is false More...
 
static double GetDoubleAttribute (XmlNode cur, string attrib)
 retrieve the double value of an attribute. Does prevent unnecessary exceptions, if the attribute is not existing More...
 
static decimal GetDecimalAttribute (XmlNode cur, string attrib)
 retrieve the decimal value of an attribute. Does prevent unnecessary exceptions, if the attribute is not existing More...
 

Protected Attributes

XmlDocument myDoc
 the XmlDocument that is currently parsed More...
 

Detailed Description

This class provides methods for parsing an XML document and assign the contents to a representation in memory.

The TXMLParser class provides an easy approach to parse elements and groups of elements of an XML document. It provides functions for easily navigate through an XML document and to retrieve attributes etc. It makes use of the .Net XML parser library.

Constructor & Destructor Documentation

◆ TXMLParser() [1/4]

Ict.Common.IO.TXMLParser.TXMLParser ( string  filename,
Boolean  withValidation 
)
inline

constructor

Parameters
filename
withValidation

◆ TXMLParser() [2/4]

Ict.Common.IO.TXMLParser.TXMLParser ( string  filename)
inline

constructor; opens the file with validation

Parameters
filename

◆ TXMLParser() [3/4]

Ict.Common.IO.TXMLParser.TXMLParser ( XmlDocument  ADoc)
inline

can be used for document that is parsed from YML

Parameters
ADocthe document that should be parsed

◆ TXMLParser() [4/4]

Ict.Common.IO.TXMLParser.TXMLParser ( TXMLParser  AReuseParser)
inline

copy constructor

Parameters
AReuseParser

Member Function Documentation

◆ FindNodeRecursive() [1/2]

static XmlNode Ict.Common.IO.TXMLParser.FindNodeRecursive ( XmlNode  AParentNode,
string  ANodeNameToSearch 
)
inlinestatic

find a node somewhere in the xml document by its tag name

Parameters
AParentNode
ANodeNameToSearch
Returns

◆ FindNodeRecursive() [2/2]

static XmlNode Ict.Common.IO.TXMLParser.FindNodeRecursive ( XmlNode  AParentNode,
string  ANodeNameToSearch,
string  ANameAttribute 
)
inlinestatic

find a node somewhere in the xml document by its tag name and attribute name

Parameters
AParentNode
ANodeNameToSearch
ANameAttribute
Returns

◆ GetAttribute()

static string Ict.Common.IO.TXMLParser.GetAttribute ( XmlNode  cur,
string  attrib 
)
inlinestatic

Retrieve an XML attribute. Empty if attribute is not present

Parameters
curthe current node
attribthe name of the attribute
Returns
the value of the attribute, or an empty string if it is not existing

◆ GetAttributeRecursive()

static string Ict.Common.IO.TXMLParser.GetAttributeRecursive ( XmlNode  cur,
string  attrib,
bool  AInheritAttributes 
)
inlinestatic

Retrieve an XML attribute. Empty if attribute is not present. Check the parent nodes, if the current node does not have that attribute

Parameters
curthe current node
attribthe name of the attribute
AInheritAttributesreturn all the values of the parent nodes as well
Returns
the value of the attribute, or the CSV list of attribute values of the parents and the node, or an empty string if the attribute is not existing

◆ GetBoolAttribute() [1/2]

static bool Ict.Common.IO.TXMLParser.GetBoolAttribute ( XmlNode  cur,
string  attrib 
)
inlinestatic

overload for GetBoolAttribute, assuming default value is false

Parameters
curthe current node
attribthe name of the attribute
Returns
the value of the attribute, or false if it is not existing

◆ GetBoolAttribute() [2/2]

static bool Ict.Common.IO.TXMLParser.GetBoolAttribute ( XmlNode  cur,
string  attrib,
bool  defaultvalue 
)
inlinestatic

retrieve the boolean value of an attribute. Understands all sorts of notation (yes|no, true|false, 0|1)

Parameters
curthe current node
attribthe name of the attribute
defaultvaluethe default value if the attribute is not existing; optional: false
Returns
the value of the attribute, or the default value if it is not existing

◆ GetChild()

static XmlNode Ict.Common.IO.TXMLParser.GetChild ( XmlNode  cur,
string  name 
)
inlinestatic

return the child with the given name, if it exists; otherwise return null

Returns
void

◆ GetDecimalAttribute()

static decimal Ict.Common.IO.TXMLParser.GetDecimalAttribute ( XmlNode  cur,
string  attrib 
)
inlinestatic

retrieve the decimal value of an attribute. Does prevent unnecessary exceptions, if the attribute is not existing

Parameters
curthe current node
attribthe name of the attribute
Returns
the value of the attribute, or -1 if it is not existing

◆ GetDocument()

XmlDocument Ict.Common.IO.TXMLParser.GetDocument ( )
inline

retrieves the document, in case the document should be parsed not by a derived class

Returns
void

◆ GetDoubleAttribute()

static double Ict.Common.IO.TXMLParser.GetDoubleAttribute ( XmlNode  cur,
string  attrib 
)
inlinestatic

retrieve the double value of an attribute. Does prevent unnecessary exceptions, if the attribute is not existing

Parameters
curthe current node
attribthe name of the attribute
Returns
the value of the attribute, or -1 if it is not existing

◆ GetIntAttribute()

static Int32 Ict.Common.IO.TXMLParser.GetIntAttribute ( XmlNode  cur,
string  attrib 
)
inlinestatic

retrieve the int value of an attribute. Does prevent unnecessary exceptions, if the attribute is not existing

Parameters
curthe current node
attribthe name of the attribute
Returns
the value of the attribute, or -1 if it is not existing

◆ GetNextEntity()

static XmlNode Ict.Common.IO.TXMLParser.GetNextEntity ( XmlNode  cur)
inlinestatic

get the next code that is a proper entity (i.e. no comment, not empty)

Parameters
curthe current node
Returns
the next node with actual content

◆ HasAttribute()

static Boolean Ict.Common.IO.TXMLParser.HasAttribute ( XmlNode  cur,
string  attrib 
)
inlinestatic

retrieve whether the node has an attribute with the given name or not

Parameters
curthe current node
attribthe name of the attribute
Returns
true if the attribute is existing

◆ NextNotBlank()

static XmlNode Ict.Common.IO.TXMLParser.NextNotBlank ( XmlNode  cur2)
inlinestatic

test the given node, if it is a comment or is empty; if it is empty, try the next nodes.

Parameters
cur2the current node
Returns
the current or the first next node with actual content

◆ RenameAttribute()

static void Ict.Common.IO.TXMLParser.RenameAttribute ( XmlNode  cur,
string  AAttribOldName,
string  AAttribNewName 
)
inlinestatic

rename an existing attribute

Parameters
cur
AAttribOldName
AAttribNewName

◆ SetAttribute()

static void Ict.Common.IO.TXMLParser.SetAttribute ( XmlNode  cur,
string  AAttribName,
string  AAttribValue 
)
inlinestatic

add or set an attribute value

Parameters
cur
AAttribName
AAttribValue

◆ XmlToString()

static string Ict.Common.IO.TXMLParser.XmlToString ( XmlDocument  ADoc)
inlinestatic

print an xml document to string; this can be necessary for transmitting between server and client, since XmlDocument is not serializable

Parameters
ADoc
Returns

◆ XmlToString2()

static string Ict.Common.IO.TXMLParser.XmlToString2 ( XmlDocument  ADoc)
inlinestatic

this is necessary to be able to store XML files that can be parsed by DTD/Schema mechanisms; for YML, we have the name of an element not as an attribute, but the element name itself; this would never work for validating xml; therefore all Elements are called XmlElement, with attribute name

Parameters
ADoc
Returns

◆ XmlToStringIndented()

static string Ict.Common.IO.TXMLParser.XmlToStringIndented ( XmlDocument  ADoc)
inlinestatic

print an xml document to string with indentation

Parameters
ADoc
Returns

Member Data Documentation

◆ myDoc

XmlDocument Ict.Common.IO.TXMLParser.myDoc
protected

the XmlDocument that is currently parsed


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